mirror of
https://github.com/Adorable-Catgirl/LuaComp.git
synced 2024-11-01 08:00:56 +11:00
experimental relative include
This commit is contained in:
parent
5b8a90da87
commit
798d60dadd
1
examples/rel_include/bar.lua
Normal file
1
examples/rel_include/bar.lua
Normal file
@ -0,0 +1 @@
|
|||||||
|
print("bar")
|
3
examples/rel_include/foo.lua
Normal file
3
examples/rel_include/foo.lua
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
--#pragma "relative_include" "y"
|
||||||
|
print("foo")
|
||||||
|
--#include "bar.lua"
|
2
examples/rel_include_test.lua
Normal file
2
examples/rel_include_test.lua
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
print("relative include test!")
|
||||||
|
--#include "rel_include/foo.lua"
|
@ -3,7 +3,17 @@
|
|||||||
-- file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
-- file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
function directives.include(env, file, asmod)
|
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
|
if not sr then return false, err end
|
||||||
--[[local f = io.open(file, "r")
|
--[[local f = io.open(file, "r")
|
||||||
local fast = mkast(f, file)
|
local fast = mkast(f, file)
|
||||||
@ -14,7 +24,7 @@ function directives.include(env, file, asmod)
|
|||||||
if env.pragmas.include_file_name == "y" then
|
if env.pragmas.include_file_name == "y" then
|
||||||
env.code = env.code .. "-- BEGIN " .. file .. "\n"
|
env.code = env.code .. "-- BEGIN " .. file .. "\n"
|
||||||
end
|
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
|
if env.pragmas.prefix_local_file_numbers == "y" then
|
||||||
local newcode = ""
|
local newcode = ""
|
||||||
local i = 1
|
local i = 1
|
||||||
|
@ -11,6 +11,7 @@ local pragma_hooks = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function directives.pragma(env, key, value)
|
function directives.pragma(env, key, value)
|
||||||
|
--luacomp.warning(key.."\t"..value)
|
||||||
if not env.pragmas[key] then
|
if not env.pragmas[key] then
|
||||||
return nil, "unknown pragma "..key
|
return nil, "unknown pragma "..key
|
||||||
end
|
end
|
||||||
|
@ -65,7 +65,8 @@ do
|
|||||||
pragmas = {
|
pragmas = {
|
||||||
include_file_name = "n",
|
include_file_name = "n",
|
||||||
prefix_local_file_numbers = "n",
|
prefix_local_file_numbers = "n",
|
||||||
wrap_includes = "n"
|
wrap_includes = "n",
|
||||||
|
relative_include = "n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
local fenv = {}
|
local fenv = {}
|
||||||
|
@ -12,4 +12,8 @@ _sv("LUACOMP_V_MAJ", 2)
|
|||||||
_sv("LUACOMP_V_MIN", 0)
|
_sv("LUACOMP_V_MIN", 0)
|
||||||
_sv("LUACOMP_V_PAT", 4)
|
_sv("LUACOMP_V_PAT", 4)
|
||||||
_sv("LUACOMP_VERSION", LUACOMP_V_MAJ.."."..LUACOMP_V_MIN.."."..LUACOMP_V_PAT)
|
_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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user