lua-users home
lua-l archive

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


Dear Luiz Henrique,

On Tue, 28 May 2013, Luiz Henrique de Figueiredo wrote:

> > 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

have many thanks for your clarification and pointer to the manual! This
__gc behaviour looks a bit counter-intuitive to me, but it's well
documented, which i had overlooked.

Regards, Hartmut