lua-users home
lua-l archive

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


On Mon, Dec 21, 2009 at 3:02 AM, spir <denis.spir@free.fr> 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?

Cheers,
Sam