From bb1bf0cf1b1a253f2ba2841bb76d726f49a06952 Mon Sep 17 00:00:00 2001 From: Sam Roxanne Date: Fri, 25 Jun 2021 11:35:25 -0500 Subject: [PATCH] =?UTF-8?q?=E2=98=A2!!WARNING!!=E2=98=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/directive_provider.lua | 1 + src/directives/loadmod.lua | 8 +++++--- src/directives/warning.lua | 4 ++++ src/libluacomp.lua | 8 ++++++-- src/luacomp_vars.lua | 2 +- tests/warning.lua | 1 + 6 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 src/directives/warning.lua create mode 100644 tests/warning.lua diff --git a/src/directive_provider.lua b/src/directive_provider.lua index 1e29a1d..4adb426 100644 --- a/src/directive_provider.lua +++ b/src/directive_provider.lua @@ -10,6 +10,7 @@ --#include "src/directives/include.lua" --#include "src/directives/loadmod.lua" --#include "src/directives/error.lua" +--#include "src/directives/warning.lua" setmetatable(directives, {__index=function(t, i) for i=1, #directive_paths do diff --git a/src/directives/loadmod.lua b/src/directives/loadmod.lua index fe908ce..df60c95 100644 --- a/src/directives/loadmod.lua +++ b/src/directives/loadmod.lua @@ -5,11 +5,13 @@ local warned = false function directives.loadmod(env, mod) if not warned then - io.stderr:write("Warning: loadmod is depreciated and unsafe. The API differs from luapreproc. Use the include paths!\n") + lc_warning("@[{_GENERATOR.fname}]", "loadmod is depreciated and unsafe. The API differs from luapreproc. Use the include paths!") warned = true end - if (not os.execute("stat "..file..">/dev/null")) then - return false, "Module `"..file.."' does not exist!" + --if (not os.execute("stat "..file..">/dev/null")) then + local sr, se = stat.stat(file) + if not sr then + return false, se end local modname, func = dofile(mod) directives[modname] = func diff --git a/src/directives/warning.lua b/src/directives/warning.lua new file mode 100644 index 0000000..f55ac36 --- /dev/null +++ b/src/directives/warning.lua @@ -0,0 +1,4 @@ +function directives.warning(env, msg) + lc_warning(env.fname, msg) + return true +end \ No newline at end of file diff --git a/src/libluacomp.lua b/src/libluacomp.lua index 61f9062..f63560f 100644 --- a/src/libluacomp.lua +++ b/src/libluacomp.lua @@ -5,13 +5,17 @@ local luacomp = {} +if arg and arg[0] == "luacomp" then + _G.luacomp = luacomp +end + local directives = {} local unistd = require("posix.unistd") local function lc_error(name, msg) if unistd.isatty(2) then - io.stderr:write(string.format("\27[90;1m(%s) \27[31;22m%s\27[0m\n", name, msg)) + io.stderr:write(string.format("\27[90;1m(%s) \27[31merror: \27[22m%s\27[0m\n", name, msg)) else io.stderr:write(string.format("(%s) %s\n", name, msg)) end @@ -20,7 +24,7 @@ end local function lc_warning(name, msg) if unistd.isatty(2) then - io.stderr:write(string.format("\27[90;1m(%s) \27[33;22m%s\27[0m\n", name, msg)) + io.stderr:write(string.format("\27[90;1m(%s) \27[33mwarning: \27[22m%s\27[0m\n", name, msg)) else io.stderr:write(string.format("(%s) %s\n", name, msg)) end diff --git a/src/luacomp_vars.lua b/src/luacomp_vars.lua index fd5db8f..1ec4067 100644 --- a/src/luacomp_vars.lua +++ b/src/luacomp_vars.lua @@ -10,6 +10,6 @@ end _sv("LUACOMP_V_MAJ", 2) _sv("LUACOMP_V_MIN", 0) -_sv("LUACOMP_V_PAT", 1) +_sv("LUACOMP_V_PAT", 2) _sv("LUACOMP_VERSION", LUACOMP_V_MAJ.."."..LUACOMP_V_MIN.."."..LUACOMP_V_PAT) _sv("LUACOMP_NAME", "LuaComp") \ No newline at end of file diff --git a/tests/warning.lua b/tests/warning.lua new file mode 100644 index 0000000..bbffb0b --- /dev/null +++ b/tests/warning.lua @@ -0,0 +1 @@ +--#warning "test" \ No newline at end of file