lua-users home
lua-l archive

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


Am 24.11.2015 um 16:42 schröbte Roberto Ierusalimschy:
I have (another) unrelated question:
After a `lua_pcall(L, 0, LUA_MULTRET, 0)`, does Lua have
`EXTRA_STACK` stack slots available for its API functions?

No. This is explained in the new release of the manual (5.3.2):

   The function results are pushed onto the stack when the function
   returns.  The number of results is adjusted to nresults, unless
   nresults is LUA_MULTRET.  In this case, all results from the function
   are pushed.  Lua takes care that the returned values fit into the
   stack space, but it does not ensure any extra space in the stack.


I.e. if I don't want to call `lua_checkstack()`, do I have to free
only the stack slots I need myself or the `EXTRA_STACK` stack slots
for the Lua API as well?

What do you mean by "free the slots"? You never free any slot; only
when the function returns its stack space is reclaimed.

I thought about reserving stack slots (using `lua_settop`) in front of the arguments/results of `lua_pcall` and then shifting the results so that there are free stack slots available at the top. However, if I can't even call Lua API functions (`lua_remove` or `lua_copy`) in a save way after the `lua_pcall`, that won't work.

Are there any functions that are guaranteed to work without any available stack slots (e.g. `lua_settop` and `lua_pop` should work, as well as `lua_checkstack`)?


-- Roberto


Philipp