garbage collection - destructors on gc-ed lua objects -
i know lua gc-ed. know lua can deal c objects via userdata.
here question: there anyway register function it's called when c userdata object gc-ed lua? [basically destructor].
thanks!
yes, there metamethod called __gc
purpose. see chapter 29 - managing resources of programming in lua (pil) more details.
the following snippet creates metatable , registers __gc
metamethod callback:
lual_newmetatable(l, "someclass"); lua_pushcfunction(l, some_class_gc_callback); lua_setfield(l, -2, "__gc");
Comments
Post a Comment