LuaComp/src/directive_provider.lua

34 lines
1.1 KiB
Lua
Raw Normal View History

2019-11-06 06:47:42 +11:00
--[[
directive_provider.lua - Provides preprocessor directives
]]
2021-06-26 02:06:38 +10:00
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at https://mozilla.org/MPL/2.0/.
2019-11-06 06:47:42 +11:00
2019-12-15 09:16:32 +11:00
--#include "src/cfg/directive_providers.lua"
2019-12-15 08:23:07 +11:00
--#include "src/directives/define.lua"
--#include "src/directives/include.lua"
--#include "src/directives/loadmod.lua"
--#include "src/directives/error.lua"
2019-12-15 09:16:32 +11:00
setmetatable(directives, {__index=function(t, i)
for i=1, #directive_paths do
2021-06-26 00:46:38 +10:00
if stat.stat(directive_paths[i].."/"..i..".lua") then
providers[i] = loadfile(directive_paths[i].."/"..i..".lua")()
return providers[i]
2019-12-15 09:16:32 +11:00
end
end
end})
local function preload_directives()
--Do this in the best way possible
for i=1, #directive_paths do
2021-06-26 00:46:38 +10:00
if stat.stat(directive_paths[i]) then
for ent in dirent.files(directive_paths[i]) do
if ent:match("%.lua$") then
providers[ent:sub(1, #ent-4)] = loadfile(directive_paths[i].."/"..ent)()
2019-12-15 09:16:32 +11:00
end
end
end
end
end