dan200 / ComputerCraft

Programmable Computers for Minecraft
Other
980 stars 198 forks source link

[1.79pr1/LuaJ] More LuaJ bugs #97

Open SquidDev opened 8 years ago

SquidDev commented 8 years ago

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:

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 :smiley:.

moomoomoo309 commented 8 years ago

Possibly related?

SquidDev commented 8 years ago

@moomoomoo309 Dan has said he won't fix that one