lua-users home
lua-l archive

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


Hello all,

I would like to re-use a LUA file loaded in a thread, from C++, but my understanding of LUA is far from perfect...

1) I create a thread with
       m_LuaState = lua_newthread(m_Manager->m_LUA);

2) I load my script with
       error = luaL_loadbuffer(m_LuaState, Buffer, l, FileNamei8);

3) I start my script with
       lua_pushnumber(m_LuaState, Param);
       result = lua_resume(m_LuaState, 1);

The first time, all's fine : my script is executed, and lua_result returns 0 (no error).

My problem is when I want to call again lua_resume on this thread : I get the error "attempt to call a nil value". And when I take a look to the m_LuaState' stack, the first time I see my loaded script :
        - top - 0
        - bot - function
but the function is removed from the stack after the first completed lua_resume...

- Does anybody know how to keep the function in the thread ?
- OR What is the good method to use several times a LUA script, but to load it only once ?

Thank you in advance for your help, I'm quite a newbie on this...

Best,
LiF