lua-users home
lua-l archive

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


Problem solved!
Problem was that I used lua_pcall to start explosion function in its thread instead of lua_resume..

On Sat, Feb 18, 2012 at 11:59 PM, curt <curt@northarc.com> wrote:

I wanted to do something almost exactly like this once, Coroutines don't really do this, so I wrote a library that does: http://northarc.com/tuna

It was designed to do exactly what you are trying to do. If you need help implementing it let me know.

-Curt



On 2/18/2012 5:38 PM, Nino Jagar wrote:
Hello,

I have two lua scripts which represents levels.
Each time a level is loaded it's respective StartLevel script is called in another thread like this:

lua_State *thr = lua_newthread(LuaMain);
lua_getglobal(thr, "StartLevel"); 
lua_pcall(thr, 0, 0, 0);

In first script I'm trying to call C function (StartExplosion) and then I want to wait until it's over.
After that I'm trying to start that coroutine again to load another level (LoadLevel) function.
I've tried returning lua_yield() from StartExplosion function and then calling lua_resume from main game loop after 10s have elapsed, but it doesn't work at all.
It seems that I need to use lua_pcallk but there is no example how to use it, can you please help me by writing a small example?
Or is it done in a completely different way?

my lua function looks like this:

**level1.lua**
function StartLevel
  StartExplosion();
  LoadLevel("level2.lua");
end

**level2.lua**
function StartLevel
  print("hello");
end


Thanks!