Cobalt table length "fix" breaks table behavior
Lustyn opened this issue · comments
Problem
I'm not entirely sure how to accurately reproduce this issue, besides just showing this (annoyingly) complex scenario:
Compiling anything using moonscript-cc (you can use moonc to reproduce this) on the latest version of CraftOS-PC is wildly broken. This does not happen in CC:T, CCEmuX, PUC Lua, or CraftOS-PC Accelerated. As a short example, here's what happens:
import a, b from require "c"
becomes
local a, b
do
local _obj_0 = require("c")
a, b = , _obj_0b
end
I tried to debug this a bit, and the basic scenario seems as such:
- A table (lets say
t
) has several items inserted usingtable.insert
#t
returns 4 (the table really does have 4 items)table.getn(t)
, for an unknown reason returns 3- Any subsequent
table.insert
calls overwrite the 4th element
You can see these artifacts in the fact that _obj_0.a
is missing entirely, _obj_0.b
is rendered as _obj_0b
, et cetera.
Fix
This is solved by simply using a commit of this Lua fork before 5517747. Not really sure what specifically in that commit causes this, but its absolutely not consistent with Cobalt 😳
Funny thing is, Cobalt used to work like this, until cc-tweaked/Cobalt#62 was merged, which fixed the inconsistencies with PUC Lua that I also broke to match. I'll be reverting it back to the original/matching behavior by v2.7.3.
I'll transfer this to craftos2 for better tracking.