Lua updating from 5.1 - LUA_GLOBALSINDEX problems

我的未来我决定 提交于 2020-01-02 08:30:07

问题


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?


回答1:


Use lua_getglobal(globalL,startgamefunction.c_str()), which works in both 5.1 and 5.2.



来源:https://stackoverflow.com/questions/11093189/lua-updating-from-5-1-lua-globalsindex-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!