Adam D. Moss | 1 Sep 2002 21:26
Picon

Re: Chunk lifetime, coroutines and threads.

Peter Loveday wrote:
> lua_pcall(...) will 'pop' all the arguments and function (or chunk) from the
> stack, so after the call you'll find your stack is now empty.
...
> lua_load (L, ...);
> 
> lua_pushvalue(L, -1); // Duplicate top item
> lua_pcall(L, 0, LUA_MULTRET, 0);
> lua_pushvalue(L, -1); // Duplicate top item
> lua_pcall(L, 0, LUA_MULTRET, 0);

Thanks!  That does work!

What exactly does lua_load() push onto the stack for popping
at execution?  ie. Since I'm passing 0 'nargs' to lua_pcall()
I presume that I don't have to push any arguments onto the
stack, so what is lua_pcall() requiring and how can I manually
derive this magic value myself so that I may push it onto the
stack every time I wish to invoke a particular chunk?

(I've looked at the lua_load() source but I can't find the
point at which it pushes this vital value; I wouldn't know
it if I saw it.)

Thanks,
--Adam
--

-- 
Adam D. Moss   . ,,^^   adam <at> gimp.org   http://www.foxbox.org/   co:3


Gmane