[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Metamethods and inheritance
- From: Dirk Laurie <dirk.laurie@...>
- Date: Tue, 31 Oct 2017 15:29:02 +0200
2017-10-31 13:32 GMT+02:00 Ulrich Schmidt <email@example.com>:
> I suggest, you take a look into middleclass
> how they do. But "__index"-ing from one table to the next to the next to the
> next .... is time consuming, so take care.
> : https://github.com/kikito/middleclass
OK, I have looked, and unless I totally misunderstand the code, the
parent class knows which subclasses it has, and propagates missing
methods into them.
I've designed a different mechanism, but it also involves keeping a
table of subclass metatables.
local metamethod = function(name)
local mmt = meta[record.tag]
local mm = assert(mmt and mmt[name],"No metamethod "..name..
" defined for "..record.tag)
-- metamethods for ~ + - to be supplied per tag
for mm in ("bnot,add,sub"):gmatch"%l+" do
mm = '__'..mm
RECORD[mm] = metamethod(mm)
`record.tag` is the name used as key in `meta` for the OBJ's.