lua-users home
lua-l archive

Re: Question about arrays...

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


On 09/06/2013 20.10, Andrew Starks wrote:
I know that in the current implementation, a sequence that also contains
hashes will still work as a sequence. That is, in my experience:
T = {"at one", "at two", property = "some value"}
...works in ipairs and with the length operator. Is this behavior that is
dependent on the implementation or is it something that is a formal part of
Lua?
I really hope so; it would break almost all of my code in the other case.
The 5.2 manual says (3.4.6):
[[ 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 integer n. In that case,
 n is its length." ]]
According to this definition, the presence or absence of non-numeric keys should be irrelevant. (by the way, if I remember correctly, once upon a time (Lua 4?) there was a magical 'n' field in arrays).
--
 Enrico

AltStyle によって変換されたページ (->オリジナル) /