lua-users home
lua-l archive

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


On Fri, Sep 4, 2015 at 2:50 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2015-09-04 4:12 GMT+02:00 Tim Hill <drtimhill@gmail.com>:
>>
>> On Sep 3, 2015, at 11:12 AM, Sean Conner <sean@conman.org> wrote:
>>
>> The following function, when invoked, causes a C stack overflow
>> in Lua 5.3.
>>
>> local subsystem_mt = {__index =
>>   function(spec,auction)
>>      for key,bid in ipairs(spec) do
>>         print("Checking '"..auction.."' against '"..key.."'")
>>      end
>>   end}
>>
>>
>> I may be missing something, but "The following function" does not seem
>> to be a function. It looks like a table... (Therefore, I do not know
>> how to invoke it to cause something.)
>>
>>
>>  All I did was take that code, then add
>>
>> x = setmetatable({},subsystem_mt)
>> print(x.one)
>>
>>
>> Isn’t this expected behavior? Since ipairs() respects metamethods (since
>> 5.3), looks like you have an infinite recursion (if you don’t have an item
>> at key 1)?
>
> The unexpected part is that you _always_ have an infinite recursion.
> Sheldon Cooper and Don Tillman would have seen this immediately,
> of course. For others, a little hint in the manual, where __index is being
> documented, would be useful.
>

As for a potential solution, consider a numeric for loop and rawget to
avoid retriggering the metamethod.

/s/ Adam