lua-users home
lua-l archive

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


Hello,


A correspondant on another list posted the following:

=================
I like some of the features of lua and php tables, but there are some really odd spots:

> t = {1, 2, [1]=3}
> return  t[1]
1
> t = {[1]=1, 2}
> return  t[1]
2

...
=================

Same behaviour by me (Lua 5.1.4). The only interpretation I can think at turns around array part optimization. Just a wild guess:
* On setting, only items with implicit index go to the optimized part. Meaning explicitely specifying [i] (with i integer) prevents it. Maybe as a consequence there can be duplicate keys? Why isn't "2" in the second case assigned to index 2?
* On reading, if the index happens to be "ordinal" (range?), then the optimized array part is first explored, possibly shadowing overriding items in the regular mapping part of the table. What happened to "[1]=3"?

What is the correct interpretation?


Denis
________________________________

vit esse estrany ☣

spir.wikidot.com