1
0
mirror of https://github.com/Adorable-Catgirl/LuaComp.git synced 2024-12-23 08:48:05 +11:00

experimental relative include

This commit is contained in:
sam 2022-02-14 21:48:54 -05:00
parent 5b8a90da87
commit 798d60dadd
7 changed files with 26 additions and 4 deletions

View File

@ -0,0 +1 @@
print("bar")

View File

@ -0,0 +1,3 @@
--#pragma "relative_include" "y"
print("foo")
--#include "bar.lua"

View File

@ -0,0 +1,2 @@
print("relative include test!")
--#include "rel_include/foo.lua"

View File

@ -3,7 +3,17 @@
-- file, You can obtain one at https://mozilla.org/MPL/2.0/.
function directives.include(env, file, asmod)
local sr, err = stat.stat(file)
local rfile = file
--luacomp.warning("relative_include\t"..env.pragmas.relative_include)
if env.pragmas.relative_include == "y" or luacomp.experimental.relative_include then
--luacomp.warning("Experimental relative include enabled!")
if not env.fname:find("/") then
rfile = file
else
rfile = env.fname:gsub("/[^/]+$", "/")..file
end
end
local sr, err = stat.stat(rfile)
if not sr then return false, err end
--[[local f = io.open(file, "r")
local fast = mkast(f, file)
@ -14,7 +24,7 @@ function directives.include(env, file, asmod)
if env.pragmas.include_file_name == "y" then
env.code = env.code .. "-- BEGIN " .. file .. "\n"
end
local code = luacomp.process_file(file, file) .. "\n"
local code = luacomp.process_file(rfile, rfile) .. "\n"
if env.pragmas.prefix_local_file_numbers == "y" then
local newcode = ""
local i = 1

View File

@ -11,6 +11,7 @@ local pragma_hooks = {
}
function directives.pragma(env, key, value)
--luacomp.warning(key.."\t"..value)
if not env.pragmas[key] then
return nil, "unknown pragma "..key
end

View File

@ -65,7 +65,8 @@ do
pragmas = {
include_file_name = "n",
prefix_local_file_numbers = "n",
wrap_includes = "n"
wrap_includes = "n",
relative_include = "n"
}
}
local fenv = {}

View File

@ -12,4 +12,8 @@ _sv("LUACOMP_V_MAJ", 2)
_sv("LUACOMP_V_MIN", 0)
_sv("LUACOMP_V_PAT", 4)
_sv("LUACOMP_VERSION", LUACOMP_V_MAJ.."."..LUACOMP_V_MIN.."."..LUACOMP_V_PAT)
_sv("LUACOMP_NAME", "LuaComp")
_sv("LUACOMP_NAME", "LuaComp")
luacomp.experimental = {
relative_include = false
}