[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: "nesting" metatables
- From: Jonathan Goble <jcgoble3@...>
- Date: Thu, 24 Dec 2015 04:29:30 -0500
On Thu, Dec 24, 2015 at 4:15 AM, Marc Balmer <email@example.com> 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.