lua-users home
lua-l archive

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


> a = {}
> setmetatable(a, a)
> a.__tostring = function() return "a tostring" end
> a.__gc = function(t) print("a gc") end

"Note that if you set a metatable without a __gc field and later create
that field in the metatable, the object will not be marked for finalization."
http://www.lua.org/manual/5.2/manual.html#2.5.1

This works:

a = { __gc = true }
setmetatable(a, a)
a.__tostring = function() return "a tostring" end
a.__gc = function(t) print("a gc") end