mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
Fix LuaJIT compatibility
This commit is contained in:
parent
fef498b3d7
commit
16d0bb8d7a
3 changed files with 33 additions and 13 deletions
|
|
@ -99,6 +99,15 @@ types.anselme = {
|
|||
end,
|
||||
to_lua = function(val)
|
||||
local l = {}
|
||||
-- handle non-pair before pairs as LuaJIT's table.insert
|
||||
-- will always insert after the last element even if there are some nil before unlike PUC
|
||||
for _, v in ipairs(val) do
|
||||
if v.type ~= "pair" then
|
||||
local s, e = to_lua(v)
|
||||
if not s and e then return s, e end
|
||||
table.insert(l, s)
|
||||
end
|
||||
end
|
||||
for _, v in ipairs(val) do
|
||||
if v.type == "pair" then
|
||||
local k, ke = to_lua(v.value[1])
|
||||
|
|
@ -106,10 +115,6 @@ types.anselme = {
|
|||
local x, xe = to_lua(v.value[2])
|
||||
if not x and xe then return x, xe end
|
||||
l[k] = x
|
||||
else
|
||||
local s, e = to_lua(v)
|
||||
if not s and e then return s, e end
|
||||
table.insert(l, s)
|
||||
end
|
||||
end
|
||||
return l
|
||||
|
|
|
|||
17
test/run.lua
17
test/run.lua
|
|
@ -144,7 +144,22 @@ else
|
|||
for _, file in ipairs(files) do
|
||||
local filebase = file:match("^(.*)%.ans$")
|
||||
local namespace = filebase:match("([^/]*)$")
|
||||
math.randomseed(0)
|
||||
-- simple random to get the same result across lua versions
|
||||
local prev = 0
|
||||
local function badrandom(a, b)
|
||||
prev = (42424242424242 * prev + 242) % 2^32
|
||||
return a + prev % (b-a+1)
|
||||
end
|
||||
function math.random(a, b)
|
||||
if not a and not b then
|
||||
return badrandom(0, 999) / 1000
|
||||
elseif not b then
|
||||
return badrandom(1, a)
|
||||
else
|
||||
return badrandom(a, b)
|
||||
end
|
||||
end
|
||||
-- load vm
|
||||
local vm = anselme()
|
||||
vm:setaliases("seen", "checkpoint", "reached")
|
||||
vm:loadfunction {
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ _[20]={}
|
|||
_[19]={}
|
||||
_[18]={}
|
||||
_[17]={}
|
||||
_[16]={tags=_[21],text="a"}
|
||||
_[15]={tags=_[20],text="a"}
|
||||
_[14]={tags=_[19],text="b"}
|
||||
_[13]={tags=_[18],text="a"}
|
||||
_[12]={tags=_[17],text="b"}
|
||||
_[16]={text="a",tags=_[21]}
|
||||
_[15]={text="b",tags=_[20]}
|
||||
_[14]={text="b",tags=_[19]}
|
||||
_[13]={text="c",tags=_[18]}
|
||||
_[12]={text="c",tags=_[17]}
|
||||
_[11]={_[16]}
|
||||
_[10]={_[15]}
|
||||
_[9]={_[14]}
|
||||
|
|
@ -24,11 +24,11 @@ return {_[1],_[2],_[3],_[4],_[5],_[6]}
|
|||
--[[
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "b"
|
||||
text = "c"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "a"
|
||||
text = "c"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
|
|
@ -36,7 +36,7 @@ return {_[1],_[2],_[3],_[4],_[5],_[6]}
|
|||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "a"
|
||||
text = "b"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue