MCJack123 / craftos2

A fast, modern, and feature-filled ComputerCraft emulator written in C++.
https://www.craftos-pc.cc
Other
217 stars 25 forks source link

Cobalt table length "fix" breaks table behavior #314

Closed Lustyn closed 1 year ago

Lustyn commented 1 year ago

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:

  1. A table (lets say t) has several items inserted using table.insert
  2. #t returns 4 (the table really does have 4 items)
  3. table.getn(t), for an unknown reason returns 3
  4. 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 😳

MCJack123 commented 1 year ago

Funny thing is, Cobalt used to work like this, until SquidDev/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.