lua-users home
lua-l archive

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

> 1) What do people think is the best practice for using these calls? Be safe
> and call them every time you push something onto the stack from C? Follow
> the (afaict) convention in Lua itself and only checkstack if you're going
> to push more than 5 objects?

Lua ensures 20 free slots when it calls a C function, exactly to avoid
the need to check the stack every time. Mostly, the code in the Lua
libraries does not check the stack when it pushes more than 5 elements,
but when it pushes an unknown number of elements (tipically inside a

> 2) Given that the stack has a maximum size, how come Lua doesn't grow the
> stack automatically when it gets full?

First, it has a (small) cost. Second, and more important, several
functions that cannot raise errors (e.g., lua_push*) would not be safe

> 3) Just to be sure that I'm understanding the docs correctly, when pushing
> a table, no matter how big it is, I only need two stack slots - one for
> lua_newtable() and one that's used for each value before lua_setfield()
> pops it off the stack. Right?


-- Roberto