lua-users home
lua-l archive

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


> This is what I do (lua 5.00alpha):
>
> L = lua_open();       // succeeds
> register_apis(L);     // succeeds
> lua_load (L, ...);    // succeeds
> lua_pcall(L, 0, LUA_MULTRET, 0); // succeeds, works, returns 0
> lua_pcall(L, 0, LUA_MULTRET, 0); // does nothing, returns LUA_ERRRUN
> lua_pcall(L, 0, LUA_MULTRET, 0); // does nothing, returns LUA_ERRRUN
> lua_pcall(L, 0, LUA_MULTRET, 0); // does nothing, returns LUA_ERRRUN
>
> I believe that ALL of those lua_pcall()s should work -- right?

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.  Try either:

lua_load (L, ...);
lua_pcall(L, 0, LUA_MULTRET, 0);
lua_load (L, ...);
lua_pcall(L, 0, LUA_MULTRET, 0);
...

or, perhaps more efficiently:

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);
...
...
lua_pop(L,1);


Love, Light and Peace,
- Peter Loveday
Director of Development, eyeon Software