lua-users home
lua-l archive

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


> You can push, pop, dup and swap to your heart's content without fear of
> corrupting it.

Well, not quite. You cannot corrupt the stack, but if you pop a string
or other garbage-collectable object, then the garbage collector might
collect it. You need to assume that the garbage collector might run
at any call to the Lua API.

So you have to watch out for the following:

const char* foo = lua_tostring(L, 2);
lua_pop(L, 1);
// foo might suddenly point to oblivion.

Reordering the stack is ok, though.

(Lua authors: any chance of implementing lua_rotate()?
Like the postscript operator rot)

R.