lua-users home
lua-l archive

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

On Sun, Nov 13, 2022 at 9:36 PM bil til <> wrote:

> ... just after thinking a bit about this (and as this is quite a
> cumbersome and tedious procedure, if I have to do this at several
> points of my C code), I thought that from my understanding of
> "invoking a function with stack", this should be NOT necessary, as on
> return the internal Lua machine anyway should strip the stack to
> exactly the same point where luaB_print was invoked.

The catch here is that this is only correct when your function is
called as a  "C function" from Lua. If it was called by another
function of yours, then the Lua stack will be preserved and the caller
will have to deal with it. It may be (badly) surprised by the extra
data on the stack.

Another thing you should pay attention to is that Lua guarantees, when
calling a C function, that the stack will have LUA_MINSTACK slots. The
C function (and whatever it calls) is responsible for calling
lua_checkstack() if more stack space is required.