wasmoon
wasmoon copied to clipboard
Unexpected behavior from arrays
Adding arrays to the environment leads to unexpected behavior:
-
table.remove
will not shift the array - Arrays have a
length
key when usingpairs
, howeveripairs
does not have this issue
const factory = new LuaFactory()
const lua = await factory.createEngine()
const env = lua.global
env.set("array_test", ["a", "b", "c"])
await lua.doString(`
table.remove(array_test, 2)
for k, v in pairs(array_test) do
print(k, v)
end
`)
0 a
1 c
2 nil
length 3
These issues do not happen when creating regular tables
await lua.doString(`
local table_test = {"a", "b", "c"}
table.remove(table_test, 2)
for k, v in pairs(table_test) do
print(k, v)
end
`)
1 a
2 c