☢!!WARNING!!☢

This commit is contained in:
Sam Roxanne 2021-06-25 11:35:25 -05:00
parent eae215ec07
commit bb1bf0cf1b
6 changed files with 18 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,4 @@
function directives.warning(env, msg)
lc_warning(env.fname, msg)
return true
end

View File

@ -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

View File

@ -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")

1
tests/warning.lua Normal file
View File

@ -0,0 +1 @@
--#warning "test"