4 ms·
Lua tables support do 0 as an index. You can also use negative numbers or floating point numbers, which can be convenient for some applications. One issue with
by bdowling 3y ago
Lua tables support do 0 as an index. You can also use negative numbers or floating point numbers, which can be convenient for some applications.
One issue with using them that way is that some Lua idioms don't work as expected. For example, "for i,v in ipairs(t) do ... end" will start iteration with i=1 and stop when it reaches an index that isn't present. Also the length operator (#) won't work as expected.
- FireInsight 3y agoWhat do you get when you get the 0-index? Does x[0]=x[1]?
- sgtnoodle 3y agoJust reading the comments here, x seems to always be a hashmap. It is implied that there's no fundamental array type in the language. So no, x[0] and x[1] do not refer to the same variable, although they certainly could compare the same depending on their specific values.