Original Post
I am currently trying to incorporate lua into my engine. everything is working fine, except for my wait() function. My wait function takes in a float, and yields the thread using lua_yield and resumes using lua_resume. it works fine in the main lua function but if i try to run other scripts in the main function, the thread hangs. Any help is appreciated: The main script test.lua this is how I'm opening the file This is my callback for 'runScript' My callback for 'wait' How i resume
function Main()
wait(1) -- waits one second, works fine
runScript("test.lua") -- runs a script
end
print("test1\n")
wait(2)
print("test2\n") -- i never see this print
m_thread = lua_newthread(m_luaVM);
luaL_dofile(m_thread, "main.lua");
lua_getglobal(m_thread, "Main"); //place the main function in the thread
lua_resume(m_thread, 0); // start the script
void runscript()
{
return luaL_dofile(m_thread, m_FileName)
}
int waitCB (lua_State *VM)
{
double floatValue = (double )lua_tonumber(VM, -1);
lua_pushnumber( VM, 0 );
//....
return lua_yield(m_thread, 0);
}
lua_resume(m_thread, 0);