[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Detecting Thread Finished
- From: RLake@...
- Date: Wed, 9 Jul 2003 11:32:18 -0500
> My question is, how can I tell when the script is complete? I figured
> lua_resume() would return some signal, but anything other than 0 seems
to
> flag an error. I could call a C function to tell me the script is done,
but
> there must be a simple way I'm missing.
lua_resume puts the script's returned results (or the arguments to yield)
on the stack.
So the simplest solution is for the script to always use:
yield()
return true
and check the top of the stack when lua_resume returns 0.
Note: lua_resume does not tell you how many results are on the stack. So
it is necessary to compare lua_gettop() after calling lua_resume with what
it was before.
Something like this, assuming we start with the thread on the top of the
stack (change -1 as appropriate):
int res = lua_gettop(L);
do {
lua_pushvalue(L, -1);
if (lua_resume(L, nargs)) lua_error(L);
/* resume left an error message on top of the stack */
} while (res == lua_gettop(L));