Lua update from 5.1 - LUA_GLOBALSINDEX problems

I recently upgraded my old Lua 5.1 project to the latest version of the library, and I had problems with LUA_GLOBALSINDEX- it became undefined. I used it only in functions lua_getfield, for example:

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 will crash. If it is 0, it works strangely, complaining of "trying to access the nil value".

My original braid is available here . How to handle LUA_GLOBALSINDEX? What should i change?

+3
source share
1 answer

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

+3

All Articles