Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua updating from 5.1 - LUA_GLOBALSINDEX problems

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?

like image 402
ThePiachu Avatar asked Sep 23 '26 18:09

ThePiachu


1 Answers

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

like image 89
lhf Avatar answered Sep 26 '26 17:09

lhf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!