diff --git a/examples/bad_include.lua b/examples/bad_include.lua new file mode 100644 index 0000000..74b92a0 --- /dev/null +++ b/examples/bad_include.lua @@ -0,0 +1,2 @@ +--#include "world.lua +print("hello"..get_world()) \ No newline at end of file diff --git a/examples/macro2.lua b/examples/macro2.lua new file mode 100644 index 0000000..371f617 --- /dev/null +++ b/examples/macro2.lua @@ -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)]] \ No newline at end of file diff --git a/examples/test.c b/examples/test.c new file mode 100644 index 0000000..d1dd29f --- /dev/null +++ b/examples/test.c @@ -0,0 +1,15 @@ +#include +/* 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; +} \ No newline at end of file diff --git a/src/generator.lua b/src/generator.lua index b54041b..c58e6ff 100644 --- a/src/generator.lua +++ b/src/generator.lua @@ -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 diff --git a/src/init.lua b/src/init.lua index dba2fa8..992396f 100644 --- a/src/init.lua +++ b/src/init.lua @@ -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)") diff --git a/src/staticinit.lua b/src/staticinit.lua new file mode 100644 index 0000000..e69de29