diff --git a/src/host/os_locate.c b/src/host/os_locate.c index 9aa33b38..6313f7a9 100644 --- a/src/host/os_locate.c +++ b/src/host/os_locate.c @@ -24,16 +24,20 @@ int do_locate(lua_State* L, const char* filename, const char* path) int os_locate(lua_State* L) { + const char* path; int i; int nArgs = lua_gettop(L); /* Fetch premake.path */ lua_getglobal(L, "premake"); lua_getfield(L, -1, "path"); + path = lua_tostring(L, -1); for (i = 1; i <= nArgs; ++i) { + const char* name = lua_tostring(L, i); + /* Direct path to file? Return as absolute path */ - if (do_isfile(lua_tostring(L, i))) { + if (do_isfile(name)) { lua_pushcfunction(L, path_getabsolute); lua_pushvalue(L, i); lua_call(L, 1, 1); @@ -41,7 +45,15 @@ int os_locate(lua_State* L) } /* do_locate(arg[i], premake.path) */ - if (do_locate(L, lua_tostring(L, i), lua_tostring(L, -1))) { + if (do_locate(L, name, path)) { + return 1; + } + + /* embedded in the executable? */ + if (premake_find_embedded_script(name)) { + lua_pushstring(L, "$/"); + lua_pushvalue(L, i); + lua_concat(L, 2); return 1; } } diff --git a/src/host/premake.c b/src/host/premake.c index 593e1a71..ae0a83bf 100644 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -461,6 +461,26 @@ static int run_premake_main(lua_State* L, const char* script) +/** + * Locate a file in the embedded script index. If found, returns the + * contents of the file's script. + */ + + const char* premake_find_embedded_script(const char* filename) + { +#if !defined(PREMAKE_NO_BUILTIN_SCRIPTS) + int i; + for (i = 0; builtin_scripts_index[i] != NULL; ++i) { + if (strcmp(builtin_scripts_index[i], filename) == 0) { + return builtin_scripts[i]; + } + } +#endif + return NULL; + } + + + /** * Load a script that was previously embedded into the executable. If * successful, a function containing the new script chunk is pushed to @@ -470,22 +490,11 @@ static int run_premake_main(lua_State* L, const char* script) int premake_load_embedded_script(lua_State* L, const char* filename) { - int i; - const char* chunk = NULL; #if !defined(NDEBUG) static int warned = 0; #endif - /* Try to locate a record matching the filename */ - #if !defined(PREMAKE_NO_BUILTIN_SCRIPTS) - for (i = 0; builtin_scripts_index[i] != NULL; ++i) { - if (strcmp(builtin_scripts_index[i], filename) == 0) { - chunk = builtin_scripts[i]; - break; - } - } - #endif - + const char* chunk = premake_find_embedded_script(filename); if (chunk == NULL) { return !OKAY; } diff --git a/src/host/premake.h b/src/host/premake.h index 08cebfb3..9f5e5c04 100644 --- a/src/host/premake.h +++ b/src/host/premake.h @@ -125,6 +125,7 @@ int string_startswith(lua_State* L); /* Engine interface */ int premake_init(lua_State* L); int premake_execute(lua_State* L, int argc, const char** argv, const char* script); +const char* premake_find_embedded_script(const char* filename); int premake_load_embedded_script(lua_State* L, const char* filename); int premake_locate_executable(lua_State* L, const char* argv0); int premake_test_file(lua_State* L, const char* filename, int searchMask);