Length of a sequential table in Lua may skip indices? -
this question has answer here:
- an interesting phenomenon of lua's table 2 answers
in lua seems if single numeric key missing table, length still continues counting:
> print(#{[1]=1,[2]=2,[4]=4}) 4
but skipping 2 indices stops @ break
> print(#{[1]=1,[2]=2,[5]=5}) 2
it's not unconvential constructor. if skipped index created after creation of table still counts past it, long break one.
> x={1,2} > print(#x) 2 > x[4]=4 > print(#x)
is implementation error or how lua supposed work. why this? references documentation of interesting.
this how works. length of table defined if table sequence, no holes. see http://www.lua.org/manual/5.2/manual.html#3.4.6 .
Comments
Post a Comment