lua-users home
lua-l archive

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

On 2/18/2012 6:32 PM, Nino Jagar wrote:
Problem solved!
Problem was that I used lua_pcall to start explosion function in its thread instead of lua_resume..

I misunderstood, I thought you were trying to pause execution inside the C routine.

On Sat, Feb 18, 2012 at 11:59 PM, curt <> wrote:

I wanted to do something almost exactly like this once, Coroutines don't really do this, so I wrote a library that does:

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


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

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:

function StartLevel

function StartLevel