I know that Lua is gc-ed. I know that Lua can deal with c objects via userdata.
Here is my question: is there anyway to register a function so that it’s called when a C userdata object is gc-ed by lua? [Basically a destructor].
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.
Yes, there is a metamethod called
__gcspecifically for this purpose. See Chapter 29 – Managing Resources of Programming in Lua (PIL) for more details.The following snippet creates a metatable and registers a
__gcmetamethod callback: