MCJack123 / craftos2

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

Long string inconsistency compared to CC:Tweaked #355

Closed MichielP1807 closed 1 month ago

MichielP1807 commented 1 month ago

Describe the bug In Lua, strings can be using long brackets. E.g. [[a]] represents a string equal to "a". The Lua documentation says that "they can contain anything except a closing bracket of the proper level." However, in Lua 5.1 it seems that they cannot contain a starting bracket of the proper level either, as this will result in a syntax error. In newer versions of Lua this does not seem to be the case.

image

This inconsistency leads to different behaviors in CraftOS-PC versus CC:Tweaked. CC:Tweaked will produce a syntax error when writing e.g. [[a[[b]], similar to Lua 5.1. CraftOS-PC will accept it as a string equal to "a[[b", similar to Lua 5.2.

To Reproduce Steps to reproduce the behavior:

  1. Open the interactive Lua console
  2. Type return [[a[[b]]
  3. See results: a syntax error if using CC:Tweaked, or a string equal to "a[[b" if using CraftOS-PC

Expected behavior The behavior seen with Lua 5.1 (which is what we also see in CC:Tweaked) could be considered a bug as it doesn't match what the documentation says. However, we expect CraftOS-PC to produce the same results as CC:Tweaked.

Environment

Additional context I found this bug while wondering why I couldn't unserialise a string with CC:Tweaked, while it did work in CraftOS-PC. In turns out it was because of the opening long brackets that appeared in the string.

CC:Tweaked: image

CraftOS-PC: image

I assume that this inconsistent behavior would also be fixed by fixing how CraftOS-PC handles the long brackets.

MCJack123 commented 1 month ago

Fixed in c819d6b