Comment by habibur

1 year ago

Add, no way to determine size of Array, which is the primary data structure anyway.

No item.length propery.

You might decide to count with foreach(), but that will terminate when it encounters the first value in the array that is NULL.

Given the way that tables work, the concept of a 'length' is a fuzzy one. However, the '#' operator will give you the last index of a table, which for tables used as arrays is pretty much what you want. There's also the '__len' metamethod, which is what's invoked if it's present if you use the '#' operator. The operator's been in the language since at least 5.1.

It's a bad idea to think of Lua tables as arrays. They're maps/dictionaries with some extra semantics to allow them to be used similarly to arrays.

> You might decide to count with foreach(), but that will terminate when it encounters the first value in the array that is NULL.

True only if the programmer doesn’t take the effort to understand the difference between ipairs and pairs.