lua-users home
lua-l archive

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


Hello all,

I'm developing a library binding and to minimize the amount of 'C' code I need to write, I want to have Lua handle the __gc metamethod. At first glance, this doesn't appear to do what I want. Here's the essence of what I'm doing:

mt = {}
mt.__gc = function() print("gc me") end
t = {1,2,3}
setmetatable(t, mt)
t = nil
collectgarbage("collect")

I would expect to see "gc me" printed after the collectgarbage function call, but I don't.

Am I completely on the wrong track? I've used __gc from 'C' code and more or less get what I expect. Is __gc usable from Lua code?

Thanks in advance for any help! When the library is done, I'll share it with y'all.

-joe