Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table.sort does not inspect the hash part #58

Closed
Wojbie opened this issue Sep 1, 2021 · 2 comments
Closed

table.sort does not inspect the hash part #58

Wojbie opened this issue Sep 1, 2021 · 2 comments

Comments

@Wojbie
Copy link

Wojbie commented Sep 1, 2021

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...
obraz
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.

@SquidDev
Copy link
Member

SquidDev commented Sep 1, 2021

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

@SquidDev
Copy link
Member

SquidDev commented Sep 1, 2021

Technically we should actually be supporting __index/__newindex here. Ughrhrhrrh.

@SquidDev SquidDev changed the title Small issue with tables created in Cobalt. table.sort does not inspect the hash part Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants