Fix preloading of embedded modules
os.locate() wasn't able to find the embedded scripts; added an explicit check after scanning the file system
This commit is contained in:
parent
cab15e8277
commit
6a66587079
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user