lua-users home
lua-l archive

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




Am 31.10.2017 um 11:24 schrieb Dirk Laurie:
I have an object with metatable RECORD and several objects which are
specialized RECORDs, with metatables OBJ1, OBJ2 etc. There are certain
methods and metamethods that are common to all RECORDs and others that
are specific to each specialization.

For non-meta methods the situation is easy: OBJ1.__index = RECORD.

However, for metamethods, access is raw. There is no other way except
copying the metamethods from RECORD into OBJ1 etc.

Or is there?

.__index can be a function instead a pointer to a 2nd table. You can do what you want in this function. I suggest, you take a look into middleclass[1] how they do. But "__index"-ing from one table to the next to the next to the next .... is time consuming, so take care.

[1]: https://github.com/kikito/middleclass