wasmoon icon indicating copy to clipboard operation
wasmoon copied to clipboard

Unexpected behavior from arrays

Open itz-coffee opened this issue 1 year ago • 2 comments

Adding arrays to the environment leads to unexpected behavior:

  • table.remove will not shift the array
  • Arrays have a length key when using pairs, however ipairs 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

itz-coffee avatar May 06 '23 09:05 itz-coffee