lua-users home
lua-l archive

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


> Oh, and what about lua_pop? Do I need to use that in every function which
> uses the lua state?

It depends. The lua VM will clean up the stack after you return to it
so in most cases its not necessary, but if you're going to be using a
dynamic amount of stack space eg pushing stuff in a loop then its wise
to use lua_pop and/or lua_checkstack so that you don't overflow the
stack. Generally if you want to use negative indices, it's best to get
the arguments out and/or convert them to absolute indices as quick as
possible (ie before you call anything that might add/remove stuff from
the stack). Personally I tend to use positive indices for the
functions actually bound into lua. Negative indices are handy for
giving an index to an aux function but the aux function should almost
always convert to a positive index (this should be easier with lua 5.2
with the introduction of lua_absindex) or get the value out first
thing.

James