[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: "nesting" metatables
- From: Marc Balmer <marc@...>
- Date: Thu, 31 Dec 2015 09:34:31 +0100
> Am 30.12.2015 um 17:17 schrieb Roberto Ierusalimschy <firstname.lastname@example.org>:
>> On Fri, Dec 25, 2015 at 12:00 AM, Jonathan Goble <email@example.com> wrote:
>>> On Thu, Dec 24, 2015 at 3:54 PM, Egor Skriptunoff
>>> <firstname.lastname@example.org> wrote:
>>>> On Thu, Dec 24, 2015 at 12:29 PM, Jonathan Goble <email@example.com>
>>>>> This metatable chaining could theoretically continue indefinitely.
>>>> The nested metatable limit is 2000 levels for Lua 5.3 (and 100 for
>>> Hence "theoretically". :)
>>> I figured there were recursion limits, as in practice stack overflow
>>> become a concern.
>> It seems that nesting of "__index" metamethods results in tail calls.
> The nesting of "__index" metamethods is done in a C loop, with no
> calls at all. The limit is there only to avoid infinite loops (with
> a table inheriting from itself).
When a nested __index metamethod is being called, does it still get the original table as the first argument, or the table that caused this __index metamethod to be called (i.e. the previously indexed table)?
If so, is the first table that was __index'ed somehow available to the nested __index metamethods?