1
0
Fork 0
mirror of https://github.com/Reuh/candran.git synced 2026-02-04 02:08:40 +00:00

feat: implement global keyword in lua55 writer

This commit is contained in:
Étienne Fildadut 2025-11-24 19:11:06 +01:00
parent e2a1c51c2d
commit 73e3f95636
5 changed files with 62 additions and 13 deletions

View file

@ -1,5 +1,15 @@
targetName = "Lua 5.4"
tags.Global = (t)
error("NYI")
end
tags.Globalrec = (t)
error("NYI")
end
tags.GlobalAll = (t)
error("NYI")
end
#placeholder("patch")
#local patch = output

View file

@ -471,6 +471,15 @@ return function(code, ast, options, macros={functions={}, variables={}})
end
return r..DESTRUCTURING_ASSIGN(destructured)
end,
-- Global{ {attributeident+} {expr+}? }
Global = (t)
local destructured = {}
local r = "global "..push("destructuring", destructured)..lua(t[1])..pop("destructuring")
if t[2][1] then
r ..= " = "..lua(t[2], "_lhs")
end
return r..DESTRUCTURING_ASSIGN(destructured)
end,
-- Let{ {ident+} {expr+}? }
Let = (t)
local destructured = {}
@ -489,6 +498,18 @@ return function(code, ast, options, macros={functions={}, variables={}})
Localrec = (t)
return "local function "..lua(t[1][1])..lua(t[2][1], "_functionWithoutKeyword")
end,
-- Globalrec{ {ident} {expr} }
Globalrec = (t)
return "global function "..lua(t[1][1])..lua(t[2][1], "_functionWithoutKeyword")
end,
-- GlobalAll{ attribute? }
GlobalAll = (t)
if #t == 1 then
return "global <" .. t[1] .. "> *"
else
return "global *"
end
end,
-- Goto{ <string> }
Goto = (t)
return "goto "..lua(t, "Id")