cc-tweaked / Cobalt

A re-entrant fork of LuaJ
Other
72 stars 13 forks source link

Reduce inconsistency with the table length operator in some cases #62

Closed Shiranuit closed 1 year ago

Shiranuit commented 1 year ago

What does this PR do ?

Fixes the issue #51

This PR tries to reduce inconsistency with the table length operator and be closer to the PUC Lua implementation.

Sorry I didn't add new test cases somehow I wasn't able to make them work on my side.

Actual version

print(#{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,nil,17,18,[33]={}})  -- 33
print(#{1,2,3,nil,5,nil,nil,8,9}) -- 5
print(#{1,2,3,nil,5,nil,7,8}) -- 3
print(#{1,2,3,nil,5,nil,7,8,9}) -- 9
print(#{1,nil,[2]=2,3}) -- 1

New Version

print(#{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,nil,17,18,[33]={}})  -- 18
print(#{1,2,3,nil,5,nil,nil,8,9}) -- 9
print(#{1,2,3,nil,5,nil,7,8}) -- 8
print(#{1,2,3,nil,5,nil,7,8,9}) -- 9
print(#{1,nil,[2]=2,3}) -- 3

PUC Lua Reference

print(#{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,nil,17,18,[33]={}})  -- 18
print(#{1,2,3,nil,5,nil,nil,8,9}) -- 9
print(#{1,2,3,nil,5,nil,7,8}) -- 8
print(#{1,2,3,nil,5,nil,7,8,9}) -- 9
print(#{1,nil,[2]=2,3}) -- 3
SquidDev commented 1 year ago

Amazing, thank you! Will add a couple of tests this evening!

SquidDev commented 1 year ago

Thank you so much!