views:

103

answers:

1

In lua, for memory allocated with lua_newuserdata, is it possible to register a destructor, so that the destructor is called when the memory region is garbage collected by lua?

Thanks!

+8  A: 

Of course it is. If the userdata has a metatable with a function called __gc, it will be called when the userdata is garbage collected, with the userdata as it's parameter. Have a look at http://www.lua.org/manual/5.1/manual.html#2.10.1

MiKy