lua-users home
lua-l archive

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


>> now my question :
>> 1/ How can I store TFUNCTION at C side ?
>> 2/ How my C code can "call" this Lua function ?

There are several ways to do it:
 * registry (see Sean Conner's answer)
 * global variable (see Sean Conner's answer)
 * probably you use the function only when dealing with some other
function or a userdata object. In the former case you can put the
function to an upvalue of another function (see lua_pushcclosure). In
the latter case you can store the function in a field of the userdata
object's environment/user value (see lua_setfenv for Lua 5.1,
lua_setuservalue for Lua 5.2).

I'd prefer third method, because it doesn't involve changing global
state (global variables or registry).


-- 


Best regards,
Boris Nagaev