lua-users home
lua-l archive

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

On Sat, Jun 19, 2004 at 05:40:43AM -0400 Dan East wrote:

[ safely storing a LUA_TFUNCTION value somewhere for later use ]

>   I am pretty new with Lua, but from what I've been able to tell, the
> LUA_TFUNCTION type represents both functions defined within Lua, as well
> as C Functions pushed in from the API side.  So it is ambiguous as to
> which type the variable actually has.
>   I have found that I can get a reference to either type by first
> calling lua_tocfunction.  If that returns NULL then the function has
> been defined within Lua, and I use lua_ref to get a reference to it.
>   To push it back on the stack, lua_pushcfunction is used (if
> lua_tocfunction returned a non-NULL value), otherwise lua_getref is used
> to push a Lua defined function.
>   I would think using references is the proper way to handle what you're
> trying to do.

References seem to be the keyword indeed. Scanning this list's archive,
I found some notes on using luaL_ref() for that which I will try now.
When I am done, I'll follow-up with a brief summary of what I've done
and how far it got me.