diff --git a/src/_premake_main.lua b/src/_premake_main.lua index ce6c2e43..a19fcbe6 100644 --- a/src/_premake_main.lua +++ b/src/_premake_main.lua @@ -68,6 +68,12 @@ name .. ".lua" } + -- If this module is being requested by an embedded script, favor embedded modules. + -- This helps prevent local scripts from interfering with release build bootstrapping. + if string.startswith(_SCRIPT_DIR, '$/') then + table.insert(paths, 1, '$/' .. full) + end + -- try to locate the module for _, p in ipairs(paths) do local file = os.locate(p) @@ -118,8 +124,9 @@ local preloader = name .. "/_preload.lua" preloader = os.locate("modules/" .. preloader) or os.locate(preloader) if preloader then - m._preloaded[name] = include(preloader) - if not m._preloaded[name] then + local modulePath = path.getdirectory(preloader) + m._preloaded[modulePath] = include(preloader) + if not m._preloaded[modulePath] then p.warn("module '%s' should return function from _preload.lua", name) end else @@ -306,9 +313,11 @@ end -- any modules need to load to support this project? - for module, func in pairs(m._preloaded) do - if not package.loaded[module] and shouldLoad(func) then - require(module) + for modulePath, func in pairs(m._preloaded) do + local moduleName = path.getbasename(modulePath) + if not package.loaded[moduleName] and shouldLoad(func) then + _SCRIPT_DIR = modulePath + require(moduleName) end end end diff --git a/src/host/os_locate.c b/src/host/os_locate.c index b72b1576..e1fab7d8 100644 --- a/src/host/os_locate.c +++ b/src/host/os_locate.c @@ -36,6 +36,12 @@ int os_locate(lua_State* L) for (i = 1; i <= nArgs; ++i) { const char* name = lua_tostring(L, i); + /* Direct path to an embedded file? */ + if (name[0] == '$' && name[1] == '/' && premake_find_embedded_script(name + 2)) { + lua_pushvalue(L, i); + return 1; + } + /* Direct path to file? Return as absolute path */ if (do_isfile(L, name)) { lua_pushcfunction(L, path_getabsolute);