Lua从5.1 - LUA_GLOBALSINDEX问题更新 [英] Lua updating from 5.1 - LUA_GLOBALSINDEX problems
问题描述
我最近更新了我的旧Lua 5.1项目到最新版本的库,我遇到了 LUA_GLOBALSINDEX
的问题 - 它变得未定义。我只在 lua_getfield
函数中使用它,像这样:
void luastartgame (void)
{
if(startgamefunction.empty())return;
lua_getfield(globalL,LUA_GLOBALSINDEX,startgamefunction.c_str()); //在Lua脚本中转到函数
int numArgs = 0;
int res = lua_pcall(globalL,numArgs,0,0);
if(!luaresf(res))//函数调用的结果是否出错?
{
return;
}
}
我尝试用一些常量整数替换它 - 如果它是不是0,我的程序崩溃。如果它是0,它运行奇怪,抱怨尝试访问nil值。
我可以使用源代码cose 此处。我应该如何处理 LUA_GLOBALSINDEX
?
使用 lua_getglobal(globalL,startgamefunction.c_str()) / code>,它在5.1和5.2中都有效。
I've recently updated my old Lua 5.1 project to the newest version of the library, and I'm having problems with LUA_GLOBALSINDEX
- it became undefined. I only used it in lua_getfield
functions, like so:
void luastartgame(void)
{
if(startgamefunction.empty())return ;
lua_getfield(globalL, LUA_GLOBALSINDEX, startgamefunction.c_str()); // go to function in Lua script
int numArgs = 0;
int res = lua_pcall(globalL,numArgs,0, 0);
if(!luaresf(res)) // did the function call result in an error?
{
return;
}
}
I tried replacing it with some constant integers - if it is something other than 0, my program crashes. If it is 0, it runs oddly, complaining about "attempting to access a nil value".
My source cose is available here. How should I handle the LUA_GLOBALSINDEX
? What should I change it to?
Use lua_getglobal(globalL,startgamefunction.c_str())
, which works in both 5.1 and 5.2.
这篇关于Lua从5.1 - LUA_GLOBALSINDEX问题更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!