Cobalt
Cobalt copied to clipboard
Small issue with tables created in Cobalt.
Found this issue when i was messing with table.sort.
print("first")
local test = {"d","a","b","c"}
table.sort(test, function(a, b) return a < b end)
for k, v in ipairs(test) do
print(k, v)
end
print("second")
local test = {[1]="d",[2]="a",[3]="b",[4]="c"}
table.sort(test, function(a, b) return a < b end)
for k, v in ipairs(test) do
print(k, v)
end
This code generates this output in Cobalt. As one can see second table is not getting sorted...
While in other lua instances it creates:
first
1 a
2 b
3 c
4 d
second
1 a
2 b
3 c
4 d
This seems to imply there is something wrong with table related logic in Cobalt.
Well, this is embarrassing. It only uses the array part. I suspect the fix here is to shift everything to use rawget
/rawset
instead of indexing array
directly.
https://github.com/SquidDev/Cobalt/blob/859205c40f1366dcf1bfff71ef7cd38038bcb221/src/main/java/org/squiddev/cobalt/LuaTable.java#L645-L675
Technically we should actually be supporting __index
/__newindex
here. Ughrhrhrrh.