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!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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