[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table.unpack(...) and the __index metamethod
- From: Tim Hill <drtimhill@...>
- Date: Fri, 13 Jun 2014 23:27:31 -0700
On Jun 13, 2014, at 11:00 PM, Coda Highland <chighland@gmail.com> wrote:
> On Fri, Jun 13, 2014 at 10:37 PM, Tim Hill <drtimhill@gmail.com> wrote:
>>
>> On Jun 13, 2014, at 5:22 PM, Thiago L. <fakedme@gmail.com> wrote:
>>
>>>>
>>>> No, the OP pointed out that the overhead of doing the metamethod test in table.unpack() is low, since it can be done once at the start of unpack(), which then chooses a (fast) rawgeti() based loop or a (generic) index metamethod loop. So you get the best of both worlds in one API.
>>>>
>>>> —Tim
>>>>
>>> What if we want raw unpacking of metatabled tables? (aka keep nil as nil)
>>
>> 1. Save metatable from table
>> 2. Set metatable on table to nil
>> 3. Unpack it
>> 4. Restore metatable
>>
>> —Tim
>>
>>
>
> Until someone sets __metatable.
>
> /s/ Adam
>
Which is a clear indication they don’t want to allow back-door access :)
Anyway, I’m not tied to this but I still think the OP had a good point. The Lua ref notes in a couple of places the raw accesses are done for speed, but he is correct in noting that you don’t need to sacrifice non-raw access for speed in this case.
—Tim
- References:
- table.unpack(...) and the __index metamethod, Kalafut, Bennett
- Re: table.unpack(...) and the __index metamethod, Dirk Laurie
- Re: table.unpack(...) and the __index metamethod, Andrew Starks
- Re: table.unpack(...) and the __index metamethod, Tim Hill
- Re: table.unpack(...) and the __index metamethod, Thiago L.
- Re: table.unpack(...) and the __index metamethod, Tim Hill
- Re: table.unpack(...) and the __index metamethod, Thiago L.
- Re: table.unpack(...) and the __index metamethod, Tim Hill
- Re: table.unpack(...) and the __index metamethod, Coda Highland