1
0
mirror of https://github.com/Adorable-Catgirl/LuaComp.git synced 2024-11-23 10:28:06 +11:00

Now only includes argparse if you compile src/staticinit.lua

This commit is contained in:
Jane Roxanne 2019-11-05 20:50:07 -05:00
parent cb396d6d3f
commit 0272d053f0
6 changed files with 28 additions and 5 deletions

2
examples/bad_include.lua Normal file
View File

@ -0,0 +1,2 @@
--#include "world.lua
print("hello"..get_world())

8
examples/macro2.lua Normal file
View File

@ -0,0 +1,8 @@
@[[function my_macro(a, b)]]
print("Hello, @[{a}]. Your lucky number is @[{b}].")
@[[end]]
@[[my_macro("world", 7)]]
@[[my_macro("user", 42)]]
@[[my_macro("Earth", 0)]]
@[[my_macro("Satna", 666)]]

15
examples/test.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
/* I really don't know why you'd do this. */
@[[function my_macro(a, b)]]
printf("Good morning, @[{a}]. Your lucky number is @[{b}].");
@[[end]]
int main() {
@[[my_macro("user", 7)]]
@[[my_macro("Steve", 24)]]
@[[my_macro("Mr. Bones", 666)]]
@[[my_macro("mother", -1)]]
@[[my_macro(os.getenv("USER"), os.getenv("UID"))]]
return 0;
}

View File

@ -53,7 +53,7 @@ local function generate(ast)
end
local env = {code = ""}
local function run_away_screaming(fpos, err)
io.stdout:write("ERROR: "..fps..": "..err.."\n")
io.stdout:write("ERROR: "..fpos..": "..err.."\n")
os.exit(1)
end
local function call_directive(fpos, dname, ...)
@ -68,7 +68,7 @@ local function generate(ast)
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!")
run_away_screaming(fpos, "Enviroment variable `"..evar.."' does not exist!")
end
env.code = env.code .. "\""..lua_escape(e).."\""
end

View File

@ -22,9 +22,7 @@
--#include "directive_provider.lua"
--#include "cfg/minifier_providers.lua"
local argparse = (function()
--#include "argparse.lua"
end)()
local argparse = require("argparse")
local parser = argparse(arg[0], "LuaComp v"..LUACOMP_VERSION.."\nA Lua preprocessor+postprocessor.")
parser:argument("input", "Input file (- for STDIN)")

0
src/staticinit.lua Normal file
View File