lua-users home
lua-l archive

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


On Sat, 2009-04-25 at 19:18 -0600, Patrick Donnelly wrote:
> On Sat, Apr 25, 2009 at 11:39 AM, Scott Parlane <scott@scottnz.com> wrote:
> > Hi,
> >
> > I was wondering what problems, if any I will have with using the
> > attached patch ?
> >
> > I call lua_pushfunction() with a value I previously got from
> > lua_topointer() from the same lua_State (but not in the same call, so
> > the function is no longer on the stack)
> 
> What you are doing is dangerous. I don't see a practical reason for
> taking this approach to putting some previously seen function on the
> stack. You should be instead using luaL_ref and luaL_unref and storing
> the integer instead of a pointer:
> 
> /* some function you may need at stack index -1 */
> saved_function_integer = luaL_ref(L, LUA_REGISTRYINDEX);
> 
> /* retrieve the function */
> lua_rawgeti(L, LUA_REGISTRYINDEX, saved_function_integer);
> 
> 
Thanks,

This does exactly what I wanted. pushfunction didn't work so well when
the function was passed in the arguments.

Regards,

Scott