ComputerCraft

ComputerCraft

21M Downloads

[1.79pr1/LuaJ] More LuaJ bugs

SquidDev opened this issue ยท 2 comments

commented

These are kinda pedantic, sorry.

string.rep on negative numbers.

string.rep should return an empty string for a negative count. It currently errors with a negative size exception.

Patch

unpack should allow nil ranges

unpack({1,2,3}, nil, nil) results in an error as it is expecting an integer. LuaJ should be using optInt rather than checkInt

Patch

Frontier pattern is broken

string.gsub ("THE (QUICK) brOWN FOx JUMPS", "%f[%a]%u+%f[%A]", print)

Results in an array out of bounds exception. Patch

tonumber does not correctly trim whitespace.

tonumber should trim all whitespace, but instead only strips spaces. Patch here and here.

tostring produces Infinity on large numbers.

local num = 1e39
print(tostring(num)) -- Infinity
print(tostring(num / 10)) -- 1e38

This is because LuaDouble.toString casts to a float before converting to a string: large numbers can be held in a double but not in a float and so are truncated. Lua uses %.14g as the number format for sprintf, though that doesn't have the same semantics in Java. Patch here.

Invalid patterns cause Java exceptions instead of Lua errors

Some invalid patterns (namely [ and %f) will throw an out of bounds exception instead of firing the appropriate Lua error.

string.find("", "[") -- throws OutOfBoundsException

The fix for this can be found here.

Other bugs

This is a list of bugs which are a pain but you may not want to fix:

  • LuaError casts to a string. This means pcall(error, {}) produces a string rather than the expected table. This can be avoided by storing both the string and LuaValue values of the object (which is what LuaJ 3 does)
  • Creating a weak table clones the object: local a = {} setmetatable(a, { __weak = 'k'}) has no effect: you have to store the value back in a. LuaJ 3 uses a different table system, but requires some additional patches to function as expected.
  • Clearing a table while iterating through it does not work (for k, v in pairs(object) do object[k] = nil). LuaJ 3.0's changes to tables could be backported to your fork as above.

Edit: Just realised it might sound like I'm trying to get you to switch to LuaJ 3.0. Sorry if it comes across that way, I'm just reporting bugs I've come across ๐Ÿ˜ƒ.

commented