From c71c1479ddec8f3288e7bc2f75204d220bb6742c Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Tue, 30 May 2023 21:12:53 +0200 Subject: [PATCH] Lua 5.3+ fixes --- build.gradle | 2 +- changelog.md | 6 +++++- .../assets/opencomputers/lua/machine.lua | 17 ++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index b10bc73fda..ca548b3232 100644 --- a/build.gradle +++ b/build.gradle @@ -162,7 +162,7 @@ dependencies { compile 'com.google.code.findbugs:jsr305:1.3.9' // Annotations used by google libs. embedded name: 'OC-LuaJ', version: '20220907.1', ext: 'jar' - embedded name: 'OC-JNLua', version: '20220928.1', ext: 'jar' + embedded name: 'OC-JNLua', version: '20230530.0', ext: 'jar' embedded name: 'OC-JNLua-Natives', version: '20220928.1', ext: 'jar' testCompile "org.mockito:mockito-all:1.10.19" diff --git a/changelog.md b/changelog.md index 039adb659a..bdd22d6ed4 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,8 @@ -## New Features/Support +## Fixes/improvements + +* Reverted Internet Card code to OC 1.7.7, fixing the many related regressions. +* Fixed "number expected, got number" being displayed instead of "number has no integer representation" on Lua 5.3+. +* Fixed math.randomseed() not working with non-integer values. ## OpenOS fixes/improvements diff --git a/src/main/resources/assets/opencomputers/lua/machine.lua b/src/main/resources/assets/opencomputers/lua/machine.lua index e32d163d52..f4b94321af 100644 --- a/src/main/resources/assets/opencomputers/lua/machine.lua +++ b/src/main/resources/assets/opencomputers/lua/machine.lua @@ -893,17 +893,19 @@ sandbox = { acos = math.acos, asin = math.asin, atan = math.atan, - atan2 = math.atan2, + atan2 = math.atan2 or math.atan, -- Deprecated in Lua 5.3 ceil = math.ceil, cos = math.cos, - cosh = math.cosh, + cosh = math.cosh, -- Deprecated in Lua 5.3 deg = math.deg, exp = math.exp, floor = math.floor, fmod = math.fmod, - frexp = math.frexp, + frexp = math.frexp, -- Deprecated in Lua 5.3 huge = math.huge, - ldexp = math.ldexp, + ldexp = math.ldexp or function(a, e) -- Deprecated in Lua 5.3 + return a*(2.0^e) + end, log = math.log, max = math.max, min = math.min, @@ -917,13 +919,14 @@ sandbox = { return spcall(math.random, ...) end, randomseed = function(seed) - spcall(math.randomseed, seed) + -- math.floor(seed) emulates pre-OC 1.8.0 behaviour + spcall(math.randomseed, math.floor(seed)) end, sin = math.sin, - sinh = math.sinh, + sinh = math.sinh, -- Deprecated in Lua 5.3 sqrt = math.sqrt, tan = math.tan, - tanh = math.tanh, + tanh = math.tanh, -- Deprecated in Lua 5.3 -- Lua 5.3. maxinteger = math.maxinteger, mininteger = math.mininteger,