[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: metatable transmission
- From: Sam Roberts <vieuxtech@...>
- Date: Mon, 21 Dec 2009 09:39:54 -0800
On Mon, Dec 21, 2009 at 3:02 AM, spir <firstname.lastname@example.org> wrote:
> This is mainly in the frame of OO & inheritance. I realized the following; but not quite sure to properly understand every point.
> Say I have a Collection type with a custom "view" method pointed by Collection's metatable __tostring key. Now, imagine I want a more specialized Sequence type inheriting from Collection, including its metatable. Sequence, indeed, has a different view; to make it work with print(), I need to let its metatable __tostring key point to the new method.
> But then --here is the trap--, Collections may now print out like Sequences, unless I have copied the metatable's _content_ instead of (a pointer to) the metatable itself.
Depends on how you implemented inheritance, doesn't it?