[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Metatable inheritance
- From: "Jose Luis Hidalgo" <joseluis.hidalgo@...>
- Date: Sat, 7 Apr 2007 20:34:43 +0200
Hi Joe,
Have a look at: http://www.lua.org/pil/16.3.html , suppose you have
an object, with a __index metatable (for methods), if that object has
a parent you can set as __index metatable of the current __index
metatable the parent table (it is much more easy that it sounds).
With that if a method is not located in the current metatable it will
take a look at the parent. If the parent has another parent the this
will work recursively, nice isn't it?
Cheers,
Jose L.
2007/4/7, Joe Krahn <jkrahn@nc.rr.com>:
I'm new to Lua, so maybe there is already something like this.
If I make my own Lua objects with several Metatable entries, my
understanding is that I will have to add these entries for every object.
If I have a lot of these object, that seems wasteful, and adds overhead
from extra memory accesses. I was thinking, how about having a metatable
entry called "__inherit", which is just a reference to another table,
and which is checked if a given entry is not found?
Joe Krahn
--
Jose L. Hidalgo Valiño (PpluX)
---- http://www.pplux.com ----