mirror of
https://github.com/Adorable-Catgirl/LuaComp.git
synced 2024-11-23 10:28:06 +11:00
Oh yeah, now it should work.
This commit is contained in:
parent
7b9d701e6f
commit
735d0b0ab3
1
examples/envvar.lua
Normal file
1
examples/envvar.lua
Normal file
@ -0,0 +1 @@
|
|||||||
|
print("The user who compiled this used "..$(SHELL))
|
1
examples/luavar.lua
Normal file
1
examples/luavar.lua
Normal file
@ -0,0 +1 @@
|
|||||||
|
print("This was made for @[{_VERSION}]")
|
3
examples/macro.lua
Normal file
3
examples/macro.lua
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@[[for i=1, 5 do]]
|
||||||
|
print("hello world @[{i}]")
|
||||||
|
@[[end]]
|
@ -1,3 +1,3 @@
|
|||||||
function get_world()
|
function get_world()
|
||||||
return "world"
|
return "world"
|
||||||
end
|
end
|
||||||
|
@ -218,7 +218,7 @@ local function mkast(f, n)
|
|||||||
add_code()
|
add_code()
|
||||||
skip(f, 2)
|
skip(f, 2)
|
||||||
local val = ""
|
local val = ""
|
||||||
while peek(f, 2) == "]]" do
|
while peek(f, 2) ~= "]]" do
|
||||||
val = val .. nextc(f)
|
val = val .. nextc(f)
|
||||||
end
|
end
|
||||||
tree[#tree+1] = {type="lua", code=val, file=n, line=lpos}
|
tree[#tree+1] = {type="lua", code=val, file=n, line=lpos}
|
||||||
@ -227,7 +227,7 @@ local function mkast(f, n)
|
|||||||
add_code()
|
add_code()
|
||||||
skip(f, 2)
|
skip(f, 2)
|
||||||
local val = ""
|
local val = ""
|
||||||
while peek(f, 2) == "}]" do
|
while peek(f, 2) ~= "}]" do
|
||||||
val = val .. nextc(f)
|
val = val .. nextc(f)
|
||||||
end
|
end
|
||||||
tree[#tree+1] = {type="lua_r", code=val, file=n, line=lpos}
|
tree[#tree+1] = {type="lua_r", code=val, file=n, line=lpos}
|
||||||
|
@ -5,6 +5,6 @@ function directives.include(env, file)
|
|||||||
local f = io.open(file, "r")
|
local f = io.open(file, "r")
|
||||||
local fast = mkast(f, file)
|
local fast = mkast(f, file)
|
||||||
local code = generate(fast)
|
local code = generate(fast)
|
||||||
env.code = env.code .. "\n" .. code
|
env.code = env.code .. "\n" .. code .. "\n"
|
||||||
return true
|
return true
|
||||||
end
|
end
|
@ -27,7 +27,7 @@ local function generate(ast)
|
|||||||
for i=1, #ast do
|
for i=1, #ast do
|
||||||
local leaf = ast[i]
|
local leaf = ast[i]
|
||||||
if (leaf.type == "lua") then
|
if (leaf.type == "lua") then
|
||||||
lua_code = lua_code .. code
|
lua_code = lua_code .. leaf.code
|
||||||
elseif (leaf.type == "directive") then
|
elseif (leaf.type == "directive") then
|
||||||
local stargs = {}
|
local stargs = {}
|
||||||
for i=1, #leaf.args do
|
for i=1, #leaf.args do
|
||||||
@ -40,7 +40,7 @@ local function generate(ast)
|
|||||||
end
|
end
|
||||||
lua_code = lua_code .. "call_directive(\""..leaf.file..":"..tostring(leaf.line).."\",\""..leaf.name.."\","..table.concat(stargs, ",")..")"
|
lua_code = lua_code .. "call_directive(\""..leaf.file..":"..tostring(leaf.line).."\",\""..leaf.name.."\","..table.concat(stargs, ",")..")"
|
||||||
elseif (leaf.type == "envvar") then
|
elseif (leaf.type == "envvar") then
|
||||||
lua_code = lua_code .. "put_env(\""..leaf.file..":"..tostring(leaf.line).."\",\""..leaf.name.."\")"
|
lua_code = lua_code .. "put_env(\""..leaf.file..":"..tostring(leaf.line).."\",\""..leaf.var.."\")"
|
||||||
elseif (leaf.type == "code") then
|
elseif (leaf.type == "code") then
|
||||||
lua_code = lua_code .. "put_code(\""..leaf.file..":"..tostring(leaf.line).."\",\"" .. lua_escape(leaf.data) .. "\")"
|
lua_code = lua_code .. "put_code(\""..leaf.file..":"..tostring(leaf.line).."\",\"" .. lua_escape(leaf.data) .. "\")"
|
||||||
elseif (leaf.type == "lua_r") then
|
elseif (leaf.type == "lua_r") then
|
||||||
@ -64,8 +64,8 @@ local function generate(ast)
|
|||||||
run_away_screaming(fpos, er)
|
run_away_screaming(fpos, er)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function put_env(fpos, env)
|
local function put_env(fpos, evar)
|
||||||
local e = os.getenv(env)
|
local e = os.getenv(evar)
|
||||||
if not e then
|
if not e then
|
||||||
run_away_screaming(fpos, "Enviroment variable `"..env.."' does not exist!")
|
run_away_screaming(fpos, "Enviroment variable `"..env.."' does not exist!")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user