[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Need some help to use TFUNCTION
- From: Nagaev Boris <bnagaev@...>
- Date: Wed, 3 Jun 2015 07:19:38 +0000
>> 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