[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pushfunction
- From: Patrick Donnelly <batrick@...>
- Date: Sat, 25 Apr 2009 19:18:57 -0600
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);
--
-Patrick Donnelly
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."
-Will Durant