mirror of https://github.com/bjornbytes/lovr.git
Fix lovr.filesystem.setRequirePath;
This commit is contained in:
parent
adee0a3012
commit
5fd20cc955
|
@ -290,13 +290,7 @@ int l_lovrFilesystemSetIdentity(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrFilesystemSetRequirePath(lua_State* L) {
|
||||
char* requirePath = strdup(luaL_checkstring(L, 1));
|
||||
char* pattern;
|
||||
lovrFilesystemClearRequirePath();
|
||||
while ((pattern = strsep(&requirePath, ";")) != NULL) {
|
||||
lovrFilesystemAddRequirePath(pattern);
|
||||
}
|
||||
free(requirePath);
|
||||
lovrFilesystemSetRequirePath(luaL_checkstring(L, 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,8 @@ void lovrFilesystemInit(const char* arg0, const char* arg1) {
|
|||
state.source = malloc(LOVR_PATH_MAX * sizeof(char));
|
||||
state.identity = NULL;
|
||||
state.isFused = true;
|
||||
vec_init(&state.requirePath);
|
||||
vec_push(&state.requirePath, "?.lua");
|
||||
vec_push(&state.requirePath, "?/init.lua");
|
||||
vec_init(&state.requirePatterns);
|
||||
lovrFilesystemSetRequirePath("?.lua;?/init.lua");
|
||||
|
||||
// Try to mount either an archive fused to the executable or an archive from the command line
|
||||
lovrFilesystemGetExecutablePath(state.source, LOVR_PATH_MAX);
|
||||
|
@ -57,19 +56,12 @@ void lovrFilesystemDestroy() {
|
|||
free(state.source);
|
||||
free(state.savePathFull);
|
||||
free(state.savePathRelative);
|
||||
vec_deinit(&state.requirePath);
|
||||
free(state.requirePath);
|
||||
vec_deinit(&state.requirePatterns);
|
||||
PHYSFS_deinit();
|
||||
memset(&state, 0, sizeof(FilesystemState));
|
||||
}
|
||||
|
||||
void lovrFilesystemAddRequirePath(const char* path) {
|
||||
vec_push(&state.requirePath, (char*) path);
|
||||
}
|
||||
|
||||
void lovrFilesystemClearRequirePath() {
|
||||
vec_clear(&state.requirePath);
|
||||
}
|
||||
|
||||
int lovrFilesystemCreateDirectory(const char* path) {
|
||||
return !PHYSFS_mkdir(path);
|
||||
}
|
||||
|
@ -145,7 +137,7 @@ const char* lovrFilesystemGetRealDirectory(const char* path) {
|
|||
}
|
||||
|
||||
vec_str_t* lovrFilesystemGetRequirePath() {
|
||||
return &state.requirePath;
|
||||
return &state.requirePatterns;
|
||||
}
|
||||
|
||||
const char* lovrFilesystemGetSaveDirectory() {
|
||||
|
@ -286,6 +278,25 @@ int lovrFilesystemSetIdentity(const char* identity) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void lovrFilesystemSetRequirePath(const char* requirePath) {
|
||||
if (state.requirePath) {
|
||||
free(state.requirePath);
|
||||
vec_clear(&state.requirePatterns);
|
||||
}
|
||||
|
||||
state.requirePath = strdup(requirePath);
|
||||
char* p = state.requirePath;
|
||||
|
||||
while (1) {
|
||||
vec_push(&state.requirePatterns, p);
|
||||
if ((p = strchr(p, ';')) != NULL) {
|
||||
*p++ = '\0';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int lovrFilesystemUnmount(const char* path) {
|
||||
return !PHYSFS_unmount(path);
|
||||
}
|
||||
|
|
|
@ -15,13 +15,12 @@ typedef struct {
|
|||
char* savePathRelative;
|
||||
char* savePathFull;
|
||||
bool isFused;
|
||||
vec_str_t requirePath;
|
||||
char* requirePath;
|
||||
vec_str_t requirePatterns;
|
||||
} FilesystemState;
|
||||
|
||||
void lovrFilesystemInit(const char* arg0, const char* arg1);
|
||||
void lovrFilesystemDestroy();
|
||||
void lovrFilesystemAddRequirePath(const char* path);
|
||||
void lovrFilesystemClearRequirePath();
|
||||
int lovrFilesystemCreateDirectory(const char* path);
|
||||
int lovrFilesystemGetAppdataDirectory(char* dest, unsigned int size);
|
||||
void lovrFilesystemGetDirectoryItems(const char* path, getDirectoryItemsCallback callback, void* userdata);
|
||||
|
@ -42,6 +41,6 @@ int lovrFilesystemMount(const char* path, const char* mountpoint, bool append);
|
|||
void* lovrFilesystemRead(const char* path, size_t* bytesRead);
|
||||
int lovrFilesystemRemove(const char* path);
|
||||
int lovrFilesystemSetIdentity(const char* identity);
|
||||
int lovrFilesystemSetSource(const char* source);
|
||||
void lovrFilesystemSetRequirePath(const char* requirePath);
|
||||
int lovrFilesystemUnmount(const char* path);
|
||||
size_t lovrFilesystemWrite(const char* path, const char* content, size_t size, bool append);
|
||||
|
|
Loading…
Reference in New Issue