Simplify filesystem arguments;

This commit is contained in:
bjorn 2021-02-25 10:45:45 -07:00
parent a09b7de545
commit f82e8112fe
3 changed files with 13 additions and 18 deletions

View File

@ -483,23 +483,18 @@ static int libLoader(lua_State* L) {
}
int luaopen_lovr_filesystem(lua_State* L) {
const char* archive = NULL;
lua_getglobal(L, "arg");
if (lua_istable(L, -1)) {
lua_getfield(L, -1, "exe");
const char* argExe = lua_tostring(L, -1);
lua_rawgeti(L, -2, 0);
const char* argGame = lua_tostring(L, -1);
lua_getfield(L, -3, "root");
const char* argRoot = luaL_optstring(L, -1, NULL);
if (lovrFilesystemInit(argExe, argGame, argRoot)) {
luax_atexit(L, lovrFilesystemDestroy);
}
lua_pop(L, 4);
} else {
archive = lua_tostring(L, -1);
lua_pop(L, 1);
if (lovrFilesystemInit(NULL, NULL, NULL)) {
luax_atexit(L, lovrFilesystemDestroy);
}
}
lua_pop(L, 1);
if (lovrFilesystemInit(archive)) {
luax_atexit(L, lovrFilesystemDestroy);
}
lua_newtable(L);

View File

@ -107,7 +107,7 @@ static size_t normalize(char* buffer, const char* path, size_t length) {
return n;
}
bool lovrFilesystemInit(const char* argExe, const char* argGame, const char* argRoot) {
bool lovrFilesystemInit(const char* archive) {
if (state.initialized) return false;
state.initialized = true;
@ -124,10 +124,10 @@ bool lovrFilesystemInit(const char* argExe, const char* argGame, const char* arg
}
// If that didn't work, try mounting an archive passed in from the command line
if (argGame) {
if (archive) {
state.source[LOVR_PATH_MAX - 1] = '\0';
strncpy(state.source, argGame, LOVR_PATH_MAX - 1);
if (lovrFilesystemMount(state.source, NULL, true, argRoot)) {
strncpy(state.source, archive, LOVR_PATH_MAX - 1);
if (lovrFilesystemMount(state.source, NULL, true, NULL)) {
return true;
}
}

View File

@ -12,7 +12,7 @@
#define LOVR_PATH_SEP '/'
#endif
bool lovrFilesystemInit(const char* argExe, const char* argGame, const char* argRoot);
bool lovrFilesystemInit(const char* archive);
void lovrFilesystemDestroy(void);
const char* lovrFilesystemGetSource(void);
bool lovrFilesystemIsFused(void);