Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
41
Task/Extend-your-language/Lua/extend-your-language.lua
Normal file
41
Task/Extend-your-language/Lua/extend-your-language.lua
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
-- Extend your language, in Lua, 6/17/2020 db
|
||||
-- not to be taken seriously, ridiculous, impractical, esoteric, obscure, arcane ... but it works
|
||||
|
||||
-------------------
|
||||
-- IMPLEMENTATION:
|
||||
-------------------
|
||||
|
||||
function if2(cond1, cond2)
|
||||
return function(code)
|
||||
code = code:gsub("then2", "[3]=load[[")
|
||||
code = code:gsub("else1", "]],[2]=load[[")
|
||||
code = code:gsub("else2", "]],[1]=load[[")
|
||||
code = code:gsub("neither", "]],[0]=load[[")
|
||||
code = "return {" .. code .. "]]}"
|
||||
local block, err = load(code)
|
||||
if (err) then error("syntax error in if2 statement: "..err) end
|
||||
local tab = block()
|
||||
tab[(cond1 and 2 or 0) + (cond2 and 1 or 0)]()
|
||||
end
|
||||
end
|
||||
|
||||
----------
|
||||
-- TESTS:
|
||||
----------
|
||||
|
||||
for i = 1, 2 do
|
||||
for j = 1, 2 do
|
||||
print("i="..i.." j="..j)
|
||||
|
||||
if2 ( i==1, j==1 )[[ then2
|
||||
print("both conditions are true")
|
||||
else1
|
||||
print("first is true, second is false")
|
||||
else2
|
||||
print("first is false, second is true")
|
||||
neither
|
||||
print("both conditions are false")
|
||||
]]
|
||||
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue