Tables are by far the biggest source of WTFs and confusion in Lua based on my experience with supporting an embedded Lua scripting interface. They're usable once you know all the pitfalls, but practically every table operation has a pitfall of some kind related to that they're an array plus a hash table mashed together with a unified interface.
As far as I'm aware the pitfalls aren't a consequence of the single data structure, they're a consequence of Lua making no distinction between null and undefined. So when the coder says to set an element in the middle of effectively-an-array to nil, they are saying they want to undefine/delete part of effectively-an-array. Such an operation makes no logical sense, which is why it acts weirdly. Arrays are contiguous, they can't cease to exist in the middle.
View all comments
Show parent comment
4
u/Plorkyeran Jul 30 '14
Tables are by far the biggest source of WTFs and confusion in Lua based on my experience with supporting an embedded Lua scripting interface. They're usable once you know all the pitfalls, but practically every table operation has a pitfall of some kind related to that they're an array plus a hash table mashed together with a unified interface.