[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: __gc and setmetatable()
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Tue, 28 May 2013 08:35:50 -0300
> 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