lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Hi,

I compile the scripts within my engine using luaL_loadstring.
After that I want to check if a function named "START" is defined and if so - call resume with that function on the top of the stack.

so if I have that script:

function START()
 print("test")
end


i check and try to start it using this code:

if(0/*returned*/ == mLuaVmState)
{//first start/resume of script
           lua_getglobal(mpLuaVm, "START");
           if (lua_isfunction(mpLuaVm, -1))
           {
               mLuaVmState = lua_resume(mpLuaVm, 0);
           }
           else
           {
               printf("agent %d: script has no START function\n", mId);
               mLuaScriptReadyToExecute = false;
           }
}

Problem is: lua_getglobal(mpLuaVm, "START"); gets me "nil" on top of the stack and I don't know why.
Any ideas?

Thank you in advance!