[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: New metamethod for method lookup
- From: Tony Finch <dot@...>
- Date: Wed, 18 Nov 2009 14:05:05 +0000
On Wed, 18 Nov 2009, Mark Feldman wrote:
> True, but there are some (relatively) minor changes that could be made which
> would open up a lot of features available to other languages that are more
> OO-friendly. One of the problems I've encountered with __index is that it
> prevents you from efficiently implementing virtual data members. Consider the
> case where "child" has a metatable "parent", and "parent" has a metatable
> "grandparent". Grandparent contains an __index function to catch any
> non-members that are accessed and handles them accordingly. However, when
> grandparent.__index is called, the value of self is set to parent, not child,
> which is totally contrary to the whole concept of "self":
But it makes sense. A metatable is like the class of an object. So
grandparent in your example is a metaclass, not a base class, and parent
is a class which is an instance of the metaclass.
f.anthony.n.finch <email@example.com> http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.