[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: metatable transmission
- From: spir <denis.spir@...>
- Date: Mon, 21 Dec 2009 12:02:57 +0100
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.
Is there something incorrect in this reasoning, or a point I'm missing?
(If not, I hope it helps future OO framework designers.)
la vita e estrany