lua-users home
lua-l archive

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

Am 24.11.2015 um 17:50 schröbte Roberto Ierusalimschy:
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`)?

All API functions that do not push stuff (as flagged in its documentaion)
should work without any available stack slots.

That criteria appears to not be sufficient, e.g. `lua_error` doesn't push elements according to the manual, but `luaG_errormsg` uses `EXTRA_STACK` space. And some `luaL_` functions might use functions that push internally (e.g. `luaL_len` or `luaL_ref`).

That includes both lua_remove and lua_copy (and lua_rotate, which
seems your best option for moving the results).

I try to target older Lua versions as well (Lua 5.2 and up since I need yieldable C functions), and a reimplementation of `lua_rotate` would have to push values for swapping ...

-- Roberto