>>23
lua is really flexible in that a table functions both as an array, and as a hash table. So internally, there is an array section that is indexed by integers, and a hash table part that is indexed by arbitrary keys. I'm not sure what the defined behavior is if you where to start assigning values into into high indecies. But on my lua:
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
a = {}
a[6] = 9
for i,v in ipairs(a) do print(i,v) end
for i,v in pairs(a) do print(i,v) end
6 9
a[1] = 34
for i,v in ipairs(a) do print(i,v) end
1 34
for i,v in pairs(a) do print(i,v) end
1 34
6 9
making assignments to the next index in the array inserts it into the array section (which gets iterated by ipairs), and the other assignments go into the hash table section. You actually could just use zero indexing, and the zero would be treated as a hash table key, and would be indexed there. The only glitch is that the zero key would not show up if you used ipairs to iterate. You could use pairs, which iterates over both the array and the hash table, but then the zero key isn't necessarily processed first. You could make your own iterator, which first returns
0, a[0], and then continues with ipairs.