I faced a problem using multiple threads in LuaJava. My application have one root LuaState which loads Scenario.lua. From this scenario callbacks to Java are maid, each callback starts new thread. Each thread runs lua function with while loop, which ones again are making callbacks to Java.
What happens:
Ones first thread is created, it starts executing Lua function which instantly makes callback to Java. When second thread is created, thread state stack is not correct, because function call parameters from
previous call are put on stack.

New threads are created like this:
   ...
       // create new thread
       newL = L.newThread();
       if(newL == null)
       {
           return 0;
       }
       // push thread function to stack
       L.getGlobal(fname);
       // put reference in LUA registry
       ref = newL.Lref(LuaState.LUA_REGISTRYINDEX);
   ...
This new state is passed to Thread which calls the thread:
   ...
   error = state.pcall(playParams.args_num, 0, 0);
   ...

Is there an example how it is done, because I could not find it?

Thanks,
Roman

_______________________________________________
Kepler-Project mailing list
Kepler-Project@lists.luaforge.net
http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
http://www.keplerproject.org/

Reply via email to