40
src/Config.c
40
src/Config.c
@@ -321,6 +321,15 @@ int config_load_ref(lua_State *L, int idx, Config *out)
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, -1, "cubemap");
|
||||
if (lua_isstring(L, -1)) {
|
||||
char const *s = lua_tostring(L, -1);
|
||||
if (s && s[0]) {
|
||||
(void)dupstr(s, (char **)&out->cubemap);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_pop(L, 1);
|
||||
return 0;
|
||||
}
|
||||
@@ -342,6 +351,11 @@ void config_unref(lua_State *L, Config *cfg)
|
||||
|
||||
free(cfg->input.keyboard.xkb_options);
|
||||
cfg->input.keyboard.xkb_options = NULL;
|
||||
|
||||
if (cfg->cubemap) {
|
||||
free((void *)cfg->cubemap);
|
||||
cfg->cubemap = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void config_trigger_ref(lua_State *L, Config *cfg, int ref)
|
||||
@@ -430,9 +444,33 @@ int config_manager_reload(ConfigManager *cm)
|
||||
|
||||
if (load_config_file(cm->L, cm->path) != 0)
|
||||
return -1;
|
||||
|
||||
int rc = config_load_ref(cm->L, -1, &cm->cfg);
|
||||
lua_pop(cm->L, 1);
|
||||
return rc;
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
|
||||
if (cm->cfg.cubemap && cm->cfg.cubemap[0] != '/') {
|
||||
char const *slash = strrchr(cm->path, '/');
|
||||
char const *dir = ".";
|
||||
size_t dirlen = 1;
|
||||
if (slash) {
|
||||
dir = cm->path;
|
||||
dirlen = (size_t)(slash - cm->path);
|
||||
}
|
||||
size_t n = dirlen + 1 + strlen(cm->cfg.cubemap)
|
||||
+ 1; // dir + '/' + hdri + '\0'
|
||||
char *full = (char *)malloc(n);
|
||||
if (full) {
|
||||
memcpy(full, dir, dirlen);
|
||||
full[dirlen] = '/';
|
||||
strcpy(full + dirlen + 1, cm->cfg.cubemap);
|
||||
free((void *)cm->cfg.cubemap);
|
||||
cm->cfg.cubemap = full;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua_State *config_manager_lua(ConfigManager *cm) { return cm ? cm->L : NULL; }
|
||||
|
||||
Reference in New Issue
Block a user