Skip to content

Commit feeb0fa

Browse files
committed
fix lua 5.2-5.4
1 parent abe3bd3 commit feeb0fa

8 files changed

Lines changed: 39 additions & 16 deletions

File tree

nattlua.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ local ARGS = _G.ARGS or {...}
2525

2626
if ARGS[1] and ARGS[1] ~= "nattlua" and ARGS[1] ~= "temp_build_output" then
2727
require("nattlua.cli")
28-
_G.RUN_CLI(unpack(ARGS))
28+
_G.RUN_CLI(table.unpack(ARGS))
2929
end
3030

3131
return m

nattlua/cli.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ function _G.RUN_CLI(cmd, ...)
5959

6060
local func = assert(default[cmd], "Unknown command " .. cmd)
6161
io.write("running ", cmd, " with arguments ", table.concat(args, " "), "\n")
62-
func(unpack(args))
62+
func(table.unpack(args))
6363
end

nattlua/parser/statements.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ function META:ParseDebugCodeStatement()
530530
return node
531531
elseif self:IsTokenType("parser_debug_code") then
532532
local token = self:ExpectTokenType("parser_debug_code")
533-
assert(loadstring("local parser = ...;" .. token.value:sub(3)))(self)
533+
assert(load("local parser = ...;" .. token.value:sub(3)))(self)
534534
local node = self:StartNode("statement", "parser_debug_code")
535535
local code = self:StartNode("expression", "value")
536536
code.value = token

nattlua/types/number.lua

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,26 @@ end
2828
GetLargestNumber = function=(self)>(TNumber | nil, nil | any),
2929
}]]
3030

31+
local VERSION = jit and "LUAJIT" or _VERSION
32+
33+
local function tostring_number(num)
34+
local s = tostring(tonumber(num))
35+
if VERSION == "LUAJIT" then return s end
36+
37+
if s == "-nan" then return "nan" end
38+
39+
if s:sub(-2) == ".0" then
40+
s = s:sub(1, -3)
41+
end
42+
43+
return s
44+
end
45+
3146
local function compute_hash(min--[[#: any]], max--[[#: any]])
3247
if max then
33-
return tostring(tonumber(min)) .. ".." .. tostring(tonumber(max))
48+
return tostring_number(min) .. ".." .. tostring_number(min)
3449
elseif min then
35-
return tostring(tonumber(min))
50+
return tostring_number(min)
3651
end
3752

3853
return "N"
@@ -97,7 +112,9 @@ end
97112
function META.Equal(a--[[#: TNumber]], b--[[#: TBaseType]])
98113
if a.Type ~= b.Type then return false, "types differ" end
99114

100-
do return a.Hash == b.Hash end
115+
do
116+
return a.Hash == b.Hash
117+
end
101118

102119
if a.Max and a.Max == b.Max and a.Data == b.Data then
103120
return true, "max values are equal"
@@ -145,7 +162,10 @@ function META:CopyLiteralness(obj--[[#: TBaseType]])
145162
if x then if x.Max then return self end end
146163
end
147164

148-
if not obj:IsLiteral() then self.Data = false self.Hash = "N" end
165+
if not obj:IsLiteral() then
166+
self.Data = false
167+
self.Hash = "N"
168+
end
149169
end
150170
end
151171

@@ -538,7 +558,6 @@ do
538558
if l.Max then obj.Max = func(l.Max, r.Max or r.Data) end
539559

540560
obj.Hash = compute_hash(obj.Data, obj.Max)
541-
542561
return obj
543562
end
544563

@@ -595,12 +614,16 @@ do
595614
end
596615

597616
local function string_to_integer(str--[[#: string]])
598-
if not jit and (_VERSION == "Lua 5.1" or _VERSION == "Lua 5.2") then
599-
str = str:lower():gsub("ull", "")
600-
str = str:gsub("ll", "")
617+
if not jit and (_VERSION == "Lua 5.1" or _VERSION == "Lua 5.2" or _VERSION == "Lua 5.3" or _VERSION == "Lua 5.4") then
618+
str = str:lower():sub(-3)
619+
if str == "ull" then
620+
str = str:sub(1, -4)
621+
elseif str:sub(-2) == "ll" then
622+
str = str:sub(1, -3)
623+
end
601624
end
602625

603-
return assert(loadstring("return " .. str))()--[[# as number]]
626+
return assert(load("return " .. str))()--[[# as number]]
604627
end
605628

606629
return {

test/tests/coverage.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local coverage = require("test.helpers.coverage")
22

33
local function collect(code)
4-
assert(loadstring(coverage.Preprocess(code, "test")))()
4+
assert(load(coverage.Preprocess(code, "test")))()
55
local res = coverage.Collect("test")
66
coverage.Clear("test")
77
return res

test/tests/nattlua/analyzer/lua.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ do --- allcases
295295
analyze(table.concat(code))
296296
end
297297

298-
if bit.tobit then
298+
if jit and bit.tobit then
299299
analyze[[
300300
-- bit operations
301301
for i=1,100 do

test/tests/nattlua/analyzer/mutation_solver.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local function covered_mutation_solver()
66
local code = assert(f:read("*all"))
77
f:close()
88
return assert(
9-
loadstring(coverage.Preprocess(code, "mutation_solver"), "@nattlua/analyzer/mutation_solver.lua")
9+
load(coverage.Preprocess(code, "mutation_solver"), "@nattlua/analyzer/mutation_solver.lua")
1010
)()
1111
end
1212

test/tests/nattlua/types/number.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ do
229229
local a_res_max
230230
local b_res_min
231231
local b_res_max
232-
local func = loadstring("local a, b = ... return a " .. operator .. " b")
232+
local func = load("local a, b = ... return a " .. operator .. " b")
233233

234234
for x = a_min, a_max do
235235
for y = b_min, b_max do

0 commit comments

Comments
 (0)