2 ms·
A list of things that I disliked when I used lua some long time back: - No break or continue in loops. Had to move those code blocks to a separate functions si
by habibur 4y ago
A list of things that I disliked when I used lua some long time back:
- No break or continue in loops. Had to move those code blocks to a separate functions simply to put a "return" mimicking break.
- No ternary operator ? : or unary ++ --
- No way to count(table) which was a frequent requirement. As basic data structure for lua had been its table. And for counting you need to write a function that iterates over the elements and counts them every time.
- Need to put "local" before every variable declared inside a function, otherwise by default it will turn into a global variable.
- And this 1 based index. Had to put a lot of -1 in code.
- kemayo 4y agoCan't speak to whether some of this is just things that've become more convenient since you used the language, but some of these aren't the case. Ternary: you can use logical operators for it (`[condition] and [if-true] or [if false]`) in most cases. Counting arrays: the # operator returns the size of an array. (But only a table used as an array. If it's being used as a hash then you're right and you're on your own for counting it.)
- pull_my_finger 4y ago> Counting arrays: the # operator returns the size of an array. (But only a table used as an array. If it's being used as a hash then you're right and you're on your own for counting it.) Lua doesn't have arrays. The # operator will give you the length of a "sequence"
- kemayo 4y agoI was using the terminology of the parent comment. :D
- pull_my_finger 4y agoI know, but the difference is important because a lot of the gotchas related to the # operator make a lot more sense and are well defined in the manual. > A table with exactly one border is called a sequence. For instance, the table {10, 20, 30, 40, 50} is a sequence, as it has only one border (5). The table {10, 20, 30, nil, 50} has two borders (3 and 5), and therefore it is not a sequence. (The nil at index 4 is called a hole.) The table {nil, 20, 30, nil, nil, 60, nil} has three borders (0, 3, and 6) and three holes (at indices 1, 4, and 5), so it is not a sequence, too. The table {} is a sequence with border 0. Note that non-natural keys do not interfere with whether a table is a sequence. > When t is a sequence, #t returns its only border, which corresponds to the intuitive notion of the length of the sequence. When t is not a sequence, #t can return any of its borders. (The exact one depends on details of the internal representation of the table, which in turn can depend on how the table was populated and the memory addresses of its non-numeric keys.)