lua-users home
lua-l archive

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


在 2012年3月13日 上午9:19,Kevin Martin <kev82@khn.org.uk> 写道:
>
> On 13 Mar 2012, at 01:13, Xavier Wang wrote:
>
> then how to store this structure? if i using malloc, then when i free this
> structure? if i use userdata, when i unanchor it?
>
> Free it when you have unregistered the callbacks for the c library, and have
> closed the lua state.
>

then maybe the better idea is save lua_State* into main userdata, like this:

struct context {
   FooState state;
   lua_State *L;
};

and using this L in callback. if I use the struct, then I still need
save the pointer to somewhere to free it, or I need save the userdata
to somewhere to ancher it from not gc. so just save lua_State *L to
main userdata used to register callback, and send the main userdata to
callback. the callback function can be put into the env table (to
ancher it) of main userdata. just like how lqt does.

but if the FooState support register multi callbacks, we still need a
table to store all callback functions to a table to ancher the
function itself.

has some better ideas? this may need define shell structure from the
original context structure. just like lqt's shell_xxx class.