lua-users home
lua-l archive

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


On manual finalization (something like fh:close()) I
reset the metatable of that userdata to nil ("I'm done
with it - never wanna see it again.").

That would not be a problem. What would be a problem is
the reverse, to put a metatable (with a __gc) into a
userdata that did not have a metatable (or that had a
metatable without a __gc).

I tend to do that too. Furthermore, I sometimes change the
metatable of an object throughout its life. For example, a
newly created socket object may have a certain set of
methods. Once you bind it to an address, or when you connect
it to some other socket, the set of available methods
changes to reflect that.  In my specific case, the __gc
metamethod is always present, and never changed.

I don't mind changing this behavior in exchange for some
functionality I may grow fond of in the future. :)

Kind regards,