[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C API - lua_next traversal of "array" table
- From: Andrew Starks <andrew@...>
- Date: Fri, 19 Aug 2016 14:07:57 -0500
On Fri, Aug 19, 2016 at 2:04 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> On Fri, Aug 19, 2016 at 6:08 PM, Viacheslav Usov <via.usov@gmail.com> wrote:
>>
>> > Such use, as the very next sentence in my message explained, makes them
>> dictionaries, not arrays.
>>
>> This distinction is made in Lua's manual, too.
>>
>> Unless a __len metamethod is given, the length of a table t is only defined
>> if the table is a *sequence*, that is, the set of its positive numeric keys
>> is equal to*{1..n}* for some non-negative integer *n*. In that case, *n* is
>> its length.
>>
>> (end)
>>
>> Either a table is a sequence or it is not; it cannot be both at the same
>> time. The term "array" is used officially either in "associative array", or
>> in the part that specifies the C language API, so it was not correct to the
>> term "array" in this discussion at all, but I'm not the only one guilty of
>> that. I think it is safe to say that where we said "array" earlier, we
>> meant "sequence".
>
> I am not sure I understand what you are saying, but it is worth
> mentioning that sequences can have non-integer keys. For instance,
> {10, 20, 30, x=13, y=print} is a valid sequence in Lua.
>
> -- Roberto
>
And so is...
{10, 20, 30, x=13, y=print, [5] = 50}
I would say that the above table contains a sequence. By that
definition, any table with a non-nil value at index `1` contains a
valid sequence.
--
Andrew Starks