lua-users home
lua-l archive

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

> > - If a <local> variable is closed (__close called), it will not be
> > called by the garbagecollector?
> No, as easily demonstrated:
> [...]

More often than not, the object has an explicit method to close it,
which may also be equal to __gc and __close(*).  So, as the OP said, you
need to take care to ensure that closed objects being accessible won't
cause issues.  However, correcting the OP, this is often the case
for "traditional" __gc metamethods, too.

First, one can call __gc explcitly through 'getmetatable'. Second, with
some tricks with weak tables, an object may still be accessible even
after it being finalized (__gc called).

So, any object should be robust regarding being accessed or closed again
after being closed, no matter whether it was through an explicit call
to "close", the __close metamethod, or the __gc metamethod.

(*) A small difference between an explicit close vs. __gc and __close
is that the former can raise an error if called over an already
closed object, while the others should not.

-- Roberto