2021-11-13 08:31:32 +00:00
|
|
|
_auRequireTable = {}
|
|
|
|
|
|
|
|
function auRequireAbs(path, invalidate)
|
|
|
|
-- this is stupid
|
|
|
|
|
|
|
|
return auRequire(_G.path.getrelative(Aurora.Settings.sAbsScripts, path), nil, invalidate)
|
|
|
|
end
|
|
|
|
|
|
|
|
function auRequire(relPath, subdir, invalidate)
|
|
|
|
-- this is stupid
|
|
|
|
|
|
|
|
local buildScripts = auGetAuroraRoot()
|
|
|
|
local premakeRequireRootCWD = Aurora.Settings.sAbsScripts
|
|
|
|
|
|
|
|
if (not subdir) then
|
|
|
|
buildScripts = premakeRequireRootCWD
|
|
|
|
else
|
|
|
|
buildScripts = buildScripts .. subdir
|
|
|
|
end
|
|
|
|
|
|
|
|
buildScripts = os.realpath(buildScripts) .. "/"
|
|
|
|
|
|
|
|
if (os.isdir(buildScripts .. relPath)) then
|
|
|
|
relPath = relPath .. (relPath:match("/[^/]*$") or ("/".. relPath)) .. ".lua"
|
|
|
|
end
|
|
|
|
|
|
|
|
if (not relPath:ends(".lua")) then
|
|
|
|
relPath = "/" .. relPath .. ".lua"
|
|
|
|
end
|
|
|
|
|
2022-03-20 08:01:11 +00:00
|
|
|
relPath = _G.path.translate(relPath)
|
|
|
|
|
2021-11-13 08:31:32 +00:00
|
|
|
if (not os.isfile(buildScripts .. relPath)) then
|
|
|
|
auFatal("Script not found: ", relPath)
|
|
|
|
end
|
|
|
|
|
|
|
|
local realPath = os.realpath(buildScripts .. relPath)
|
|
|
|
|
|
|
|
-- premake should support modules.loaded[modname] (iirc), but either way, i'm being extra safe
|
|
|
|
-- we once used rel paths with require so this was required
|
|
|
|
-- invalidation requests don't seem to make much sense, but they can stay in a hint
|
|
|
|
-- wont remove this for.now
|
|
|
|
local cache = _auRequireTable[realPath]
|
|
|
|
if (cache and not invalidate) then
|
|
|
|
return cache
|
|
|
|
end
|
|
|
|
|
|
|
|
local result = require(realPath:sub(1, #realPath - 4))
|
|
|
|
_auRequireTable[realPath] = result
|
|
|
|
return result
|
2022-03-20 08:01:11 +00:00
|
|
|
end
|