[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C API - lua_next traversal of "array" table
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 19 Aug 2016 16:04:11 -0300
> 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