Forums » Bugs

Lua - ipairs() and # issues on Linux/Android

Feb 08, 2023 draugath link
There appears to be a problem using the `#` operator and `ipairs()` on some of the vanilla client tables, on the Linux and Android clients. The problem does not appear to manifest on Windows.

The error message in the output below was originally reported to me by another player on Linux. Two players on Windows had zero issues.

This was tested on a client with no plugins except one consisting of the code below, after closing and restarting the client.

When executing the function below, the game is returning the output following the function. However, if the `#` or `for...end` blocks are run directly in the console they return the expected values.
/lua console_print(#FactionTable)
13

/lua for i, v in ipairs(FactionTable) do console_print(i, v) end
-- prints stuff

--------------------------------------------------------------
Test function with odd behavior
--------------------------------------------------------------
local mytable = {
"index 1",
"index 2",
"index 3",
[101] = "index 101",
[102] = "index 102",
[103] = "index 103",
}

declare("ipairstest", function()
console_print("#mytable", #mytable)
for i, v in ipairs(mytable) do
console_print(i, v)
end

console_print("#FactionColor", #FactionColor)
for i, v in ipairs(FactionColor) do
console_print(i, v)
end

console_print("#FactionColor_RGB", #FactionColor_RGB)
for i, v in ipairs(FactionColor_RGB) do
console_print(i, v)
end

console_print("#ShipPalette_string", #ShipPalette_string)
for i, v in ipairs(ShipPalette_string) do
console_print(i, v)
end
end)

-----------------------------------------------------------------
Output
-----------------------------------------------------------------
#mytable 3
1 index 1
2 index 2
3 index 3
#FactionColor 0
101 100 100 100
103 175 175 175
105 255 255 255
102 135 135 135
104 215 215 215
#FactionColor_RGB 0
#ShipPalette_string 0
invalid key to 'next'
stack traceback:
vo/error.lua:78: in function <vo/error.lua:77>
[C]: in function 'next'
vo/vo.lua:2132: in function '(for generator)'
plugins/ipairstest/main.lua:27: in function 'ipairstest'
[string "console"]:1: in function 'func'
vo/vo_console.lua:103: in function <vo/vo_console.lua:69>
(tail call): ?
Feb 09, 2023 draugath link
I wanted to point out that this may be a problem with other tables as well, but the three in the above function are the only ones that I tested.
Feb 09, 2023 raybondo link
Tonight's patch should fix the issue with ipairs and the # operator.
Please let us know if there are any other issues.
Feb 10, 2023 Xeha link
So it wasnt just me as i first assumed. Thanks draugath for taking a proper look and reporting it, thanks ray for fixing it :)