You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the # unary operator on a lua array that has index = value, the returned length is the highest index.
Example
print(#{
[20] =0;
[600] =0;
}) --Output: 600
Expected behaviour
print(#{
[20] =0;
[600] =0;
}) --Output: 0
How the length operator should work
The length operator returns the last numeric key whose value is not nil for tables starting from 1. The length operator returns zero for tables when the first numeric key is nil or there are no numeric keys.
The text was updated successfully, but these errors were encountered:
The length operator returns the last numeric key whose value is not nil for tables starting from 1. The length operator returns zero for tables when the first numeric key is nil or there are no numeric keys.
No.
According to Lua manual, the length operator applied on a table returns a border in that table. A border in a table is any positive integer index present in the table that is followed by an absent index.
The table {[20]=0, [600]=0} has 3 borders: 0, 20 and 600.
So, #{[20]=0, [600]=0} may return any of these 3 numbers, all of them are correct.
Issue
When using the
#
unary operator on a lua array that hasindex = value
, the returned length is the highest index.Example
Expected behaviour
How the length operator should work
The length operator returns the last numeric key whose value is not nil for tables starting from 1. The length operator returns zero for tables when the first numeric key is nil or there are no numeric keys.
The text was updated successfully, but these errors were encountered: