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()
|
||||
return "world"
|
||||
end
|
||||
end
|
||||
|
@ -218,7 +218,7 @@ local function mkast(f, n)
|
||||
add_code()
|
||||
skip(f, 2)
|
||||
local val = ""
|
||||
while peek(f, 2) == "]]" do
|
||||
while peek(f, 2) ~= "]]" do
|
||||
val = val .. nextc(f)
|
||||
end
|
||||
tree[#tree+1] = {type="lua", code=val, file=n, line=lpos}
|
||||
@ -227,7 +227,7 @@ local function mkast(f, n)
|
||||
add_code()
|
||||
skip(f, 2)
|
||||
local val = ""
|
||||
while peek(f, 2) == "}]" do
|
||||
while peek(f, 2) ~= "}]" do
|
||||
val = val .. nextc(f)
|
||||
end
|
||||
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 fast = mkast(f, file)
|
||||
local code = generate(fast)
|
||||
env.code = env.code .. "\n" .. code
|
||||
env.code = env.code .. "\n" .. code .. "\n"
|
||||
return true
|
||||
end
|
@ -27,7 +27,7 @@ local function generate(ast)
|
||||
for i=1, #ast do
|
||||
local leaf = ast[i]
|
||||
if (leaf.type == "lua") then
|
||||
lua_code = lua_code .. code
|
||||
lua_code = lua_code .. leaf.code
|
||||
elseif (leaf.type == "directive") then
|
||||
local stargs = {}
|
||||
for i=1, #leaf.args do
|
||||
@ -40,7 +40,7 @@ local function generate(ast)
|
||||
end
|
||||
lua_code = lua_code .. "call_directive(\""..leaf.file..":"..tostring(leaf.line).."\",\""..leaf.name.."\","..table.concat(stargs, ",")..")"
|
||||
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
|
||||
lua_code = lua_code .. "put_code(\""..leaf.file..":"..tostring(leaf.line).."\",\"" .. lua_escape(leaf.data) .. "\")"
|
||||
elseif (leaf.type == "lua_r") then
|
||||
@ -64,8 +64,8 @@ local function generate(ast)
|
||||
run_away_screaming(fpos, er)
|
||||
end
|
||||
end
|
||||
local function put_env(fpos, env)
|
||||
local e = os.getenv(env)
|
||||
local function put_env(fpos, evar)
|
||||
local e = os.getenv(evar)
|
||||
if not e then
|
||||
run_away_screaming(fpos, "Enviroment variable `"..env.."' does not exist!")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user