lua-users home
lua-l archive

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

I find life is a lot easier if you just work with negative stack indexes,
which of course represent a relative position from the top of the stack.

Using this system, -1 is always the item at the "top" of the stack, -2 is
the item underneath that item, and so on. And of course each stack position
requires a pop to get the value off, so an item at position -1 comes off
with one pop, position -2 takes two pops, etc.


lua_pushstring (L , "BOB")

"BOB" is at stack position -1, at the top of the stack.
lua_pushnumber (L , 123);

now "BOB" is at stack position -2 and 123 is at the top.

I've never really used the whole positive index scheme. I'm not entirely
sure what the ramifications of this are.. Code that's easier to read and
understand but ends up being less efficient in some cases? Maybe I'm just
not doing anything that requires me to do that? Beats me..

> I don't understand.  Don't values get pushen onto the bottom of the
> Or are tables different?  In that case wouldn't the table be at -1??  When
> call 'C' functions from lua with numbers as parameters, I can find them on
> the bottom of the stack.  This is confusing.