lua-users home
lua-l archive

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


> This __gc behaviour looks a bit counter-intuitive to me

The motivation is to avoid checking all live objects to see if they have
to be put into the finalizable list. Thus, we only test this when the
object gets a metatable. The assumption is that most objects do not have
__gc methods and the ones that do have one set at that point, which
is typically when they are created as objects of a class or something
similar. As I said in my previous message, it is enough that the __gc
is set at the time the metatable is given to the object; the actual
value does not matter (hence __gc=true in my code) and can be changed
later. What is not supported is the addition of a __gc method after the
object has been given a metatable, as you have discovered.