[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: PATCH: 51w6 inheritable liolib + posix.popen (was PATCH: Lua5.0.2 popen/pclose fix)
- From: Mike Pall <mikelu-0506@...>
- Date: Fri, 3 Jun 2005 13:08:32 +0200
Mark Hamburg wrote:
> It should probably be noted that this sort of trick only works for classes
> that don't expect to inherit any metamethods.
Yes, you are right. Thank you for the hint.
I guess I should rephrase that:
[...] And you need to override any methods from
the superclass that may make the subclass userdata inconsistent.
You must override or copy all metamethods from superclases
since these are not inherited.
> Is there a particular reason why metamethod search doesn't obey __index
Metamethods are cached (or rather the non-existence of some of
them). This is done with a few bits in the table anchor structure
(of a metatable). A cache bit is set when a metamethod is
looked up, but not found. The cache is invalidated when the
metatable is modified.
This simple scheme no longer works with recursive metamethod
lookups. It would require an exhaustive search every time.
While this is not so bad for __index (which is the reason why
most tables have metatables in the first place), it's pretty
bad for __mode (needed by the GC on every traversal).