[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: when do programs set metatable?
- From: Diego Nehab <diego@...>
- Date: Sat, 9 Feb 2008 16:56:37 -0500 (EST)
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. :)