From bda1d10e4a836d4c9341747b57ec935ecd7e9161 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Sat, 14 Mar 2015 14:21:54 -0400 Subject: [PATCH] Clean up module file error handling; use os.locate() to predetermine script availability --- src/_premake_main.lua | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/_premake_main.lua b/src/_premake_main.lua index bd578937..24b9e63f 100644 --- a/src/_premake_main.lua +++ b/src/_premake_main.lua @@ -33,7 +33,7 @@ return { m.installModuleLoader, m.prepareEnvironment, - m.loadCoreModules, + m.preloadModules, m.runSystemScript, m.locateUserScript, m.prepareAction, @@ -76,22 +76,18 @@ dir = base end - local function try(name) - local chunk, err = loadfile(name) - if not chunk and not err:startswith("cannot open") then - error(err, 0) - end - return chunk + local full = dir .. "/" .. base .. ".lua" + local p = os.locate("modules/" .. full) or + os.locate(full) or + os.locate(name .. ".lua") + + if not p then + return "\n\tno file " .. name .. " on module paths" end - -- Premake standard is moduleName/moduleName.lua - local relPath = dir .. "/" .. base .. ".lua" - local chunk = try("modules/" .. relPath) or - try(relPath) or - try(name .. ".lua") - + local chunk, err = loadfile(p) if not chunk then - return "\n\tno file " .. name .. " on module paths" + error(err, 0) end return chunk @@ -115,7 +111,7 @@ -- and expected to be present at startup. --- - function m.loadCoreModules() + function m.preloadModules() for i = 1, #modules do local name = modules[i] local preload = name .. "/_preload.lua"