lua-users home
lua-l archive

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


On Thu, Dec 24, 2015 at 4:15 AM, Marc Balmer <marc@msys.ch> wrote:
> Is it possible to define a metatable that has a table of functions as the __index element, and then, trigger another metatable when a key is not found up in __index?

Set a metatable for the table of functions, with __index set to your
catch-all index function.

In other words, if __index is a table, and that table doesn't contain
the key, then Lua will check if that table has a metatable of its own
with an __index metamethod. This metatable chaining could
theoretically continue indefinitely.