mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
Add anonymous functions
This commit is contained in:
parent
2c6d66c222
commit
5e441886c0
15 changed files with 352 additions and 110 deletions
|
|
@ -125,7 +125,12 @@ if args.script or args.game then
|
|||
print("error", err)
|
||||
end
|
||||
if args.save then
|
||||
print(inspect(vm:save()))
|
||||
local s, e = vm:save()
|
||||
if s then
|
||||
print(inspect(s))
|
||||
else
|
||||
print(("Error while saving: %s"):format(e))
|
||||
end
|
||||
end
|
||||
|
||||
-- test mode
|
||||
|
|
@ -147,7 +152,7 @@ else
|
|||
-- simple random to get the same result across lua versions
|
||||
local prev = 0
|
||||
local function badrandom(a, b)
|
||||
prev = (42424242424242 * prev + 242) % 2^32
|
||||
prev = (15485863 * prev + 11) % 2038074743
|
||||
return a + prev % (b-a+1)
|
||||
end
|
||||
function math.random(a, b)
|
||||
|
|
|
|||
21
test/tests/anonymous function.ans
Normal file
21
test/tests/anonymous function.ans
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
:f = $(x)x*x
|
||||
|
||||
:$g(x)
|
||||
@x*x
|
||||
|
||||
{f(5)} = {g(5)}
|
||||
|
||||
{f(2)} = {g(2)}
|
||||
|
||||
:y = 5
|
||||
:h = $(x)x*x+y
|
||||
|
||||
{h(3)} == 14
|
||||
|
||||
~ y := 7
|
||||
|
||||
{h(5)} == 32
|
||||
|
||||
:i = $y*y
|
||||
|
||||
{i} == 49
|
||||
81
test/tests/anonymous function.lua
Normal file
81
test/tests/anonymous function.lua
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
local _={}
|
||||
_[35]={}
|
||||
_[34]={}
|
||||
_[33]={}
|
||||
_[32]={}
|
||||
_[31]={}
|
||||
_[30]={}
|
||||
_[29]={}
|
||||
_[28]={}
|
||||
_[27]={}
|
||||
_[26]={}
|
||||
_[25]={}
|
||||
_[24]={}
|
||||
_[23]={tags=_[35],text=" == 49"}
|
||||
_[22]={tags=_[34],text="49"}
|
||||
_[21]={tags=_[33],text=" == 32"}
|
||||
_[20]={tags=_[32],text="32"}
|
||||
_[19]={tags=_[31],text=" == 14"}
|
||||
_[18]={tags=_[30],text="14"}
|
||||
_[17]={tags=_[29],text="4"}
|
||||
_[16]={tags=_[28],text=" = "}
|
||||
_[15]={tags=_[27],text="4"}
|
||||
_[14]={tags=_[26],text="25"}
|
||||
_[13]={tags=_[25],text=" = "}
|
||||
_[12]={tags=_[24],text="25"}
|
||||
_[11]={_[22],_[23]}
|
||||
_[10]={_[20],_[21]}
|
||||
_[9]={_[18],_[19]}
|
||||
_[8]={_[15],_[16],_[17]}
|
||||
_[7]={_[12],_[13],_[14]}
|
||||
_[6]={"return"}
|
||||
_[5]={"text",_[11]}
|
||||
_[4]={"text",_[10]}
|
||||
_[3]={"text",_[9]}
|
||||
_[2]={"text",_[8]}
|
||||
_[1]={"text",_[7]}
|
||||
return {_[1],_[2],_[3],_[4],_[5],_[6]}
|
||||
--[[
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "25"
|
||||
}, {
|
||||
tags = {},
|
||||
text = " = "
|
||||
}, {
|
||||
tags = {},
|
||||
text = "25"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "4"
|
||||
}, {
|
||||
tags = {},
|
||||
text = " = "
|
||||
}, {
|
||||
tags = {},
|
||||
text = "4"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "14"
|
||||
}, {
|
||||
tags = {},
|
||||
text = " == 14"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "32"
|
||||
}, {
|
||||
tags = {},
|
||||
text = " == 32"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "49"
|
||||
}, {
|
||||
tags = {},
|
||||
text = " == 49"
|
||||
} } }
|
||||
{ "return" }
|
||||
]]--
|
||||
|
|
@ -4,11 +4,11 @@ _[20]={}
|
|||
_[19]={}
|
||||
_[18]={}
|
||||
_[17]={}
|
||||
_[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]}
|
||||
_[16]={tags=_[21],text="c"}
|
||||
_[15]={tags=_[20],text="a"}
|
||||
_[14]={tags=_[19],text="c"}
|
||||
_[13]={tags=_[18],text="b"}
|
||||
_[12]={tags=_[17],text="c"}
|
||||
_[11]={_[16]}
|
||||
_[10]={_[15]}
|
||||
_[9]={_[14]}
|
||||
|
|
@ -26,21 +26,21 @@ return {_[1],_[2],_[3],_[4],_[5],_[6]}
|
|||
tags = {},
|
||||
text = "c"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "b"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "c"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "b"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "b"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "a"
|
||||
} } }
|
||||
{ "text", { {
|
||||
tags = {},
|
||||
text = "c"
|
||||
} } }
|
||||
{ "return" }
|
||||
]]--
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
local _={}
|
||||
_[1]={"error","can't find function or variable named \"b\"; at test/tests/function scope wrong.ans:4"}
|
||||
_[1]={"error","can't find function or variable named \"b\" in namespace \"function scope wrong.\"; at test/tests/function scope wrong.ans:4"}
|
||||
return {_[1]}
|
||||
--[[
|
||||
{ "error", "can't find function or variable named \"b\"; at test/tests/function scope wrong.ans:4" }
|
||||
{ "error", "can't find function or variable named \"b\" in namespace \"function scope wrong.\"; at test/tests/function scope wrong.ans:4" }
|
||||
]]--
|
||||
Loading…
Add table
Add a link
Reference in a new issue