lua-users home
lua-l archive

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


On Fri, Dec 12, 2008 at 11:06 AM, Robert Stehwien <rstehwien@gmail.com> wrote:
> I thought I'd use luaL_ref, keep a struct for callback information.  But I
> was missing another bit of information.  luaL_ref() pops a value off the
> stack but I'm not popping the stack, just looping through it.   So do I need
> to change my loop to pop or do some dance to move the function to the top of
> the stack pop it using luaL_ref() then put it back where it was?

it's usually better to use the stack as a stack, that is, pop values
until it's empty.

but, if you have good reason to iterate over it, _and_ have to use a
stack-based function (that pops the top to get its parameters), then
simply copy the value from the iterated point to the top.  when
luaL_ref() pops it, the stack will be as before.

simply think in small steps, where each has a simple effect on the
stack.  in this case the copy-call sequence (as a whole) wouldn't
mangle the stack.


-- 
Javier