3 ms·
There's a lot to like about Lua but the one thing that stops me taking it seriously is that it doesn't have arrays or lists. Its only data structure is an infin
by rogual 10y ago
There's a lot to like about Lua but the one thing that stops me taking it seriously is that it doesn't have arrays or lists. Its only data structure is an infinite associative map (called a table), in which all keys map to the value "nil" unless otherwise set.
When you need a list, convention is to use a table with integer keys. But, the standard library functions dealing with these "lists" interpret the list as ending at the first element whose value is nil! There is no separate length field or anything (there was, but they took it out).
So, you can't just trust that a list is a generic structure that can hold anything -- you need to be on the lookout for "nil", because inserting it into a list truncates the list to that position.
There are many crazy workarounds for this: http://lua-users.org/wiki/StoringNilsInTables http://lua-users.org/wiki/StoringNilsInTables
But my workaround is to just not use Lua, because as many warts as JS has, it has nothing as bad as that IMO. It's a shame, because Lua is otherwise an excellent language.