Re: C API - lua_next traversal of "array" table
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: C API - lua_next traversal of "array" table
- From: Ross Berteig <Ross@...>
- Date: 2016年8月19日 18:02:20 -0700
On 8/19/2016 10:13 AM, Viacheslav Usov wrote:
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.
What you missed is the phrase "set of its positive numeric keys". That
does not require that there be no non-positive numeric keys. Or that
there be no keys that are not numbers at all, perhaps strings or any
other type allowed as a key.
That distinction is important.
So t={1,2,3,4,5, x=13, y=print, [{}]="hard to index"} is certainly a
sequence. It remains a sequence if elements at t[0] or t[-1] are defined
as well, but those non-positive numbered keys are not part of the sequence.
--
Ross Berteig Ross@CheshireEng.com
Cheshire Engineering Corp. http://www.CheshireEng.com/
+1 626 303 1602