From cbe8656511c8aeefa3020cdeec57179fd9ffa61e Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 10 Aug 2021 17:28:56 +1000 Subject: Read configs with the newish Lua2hashtbl(). Though this will change again. --- src/sledjchisl/sledjchisl.c | 45 ++++----------------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) (limited to 'src/sledjchisl/sledjchisl.c') diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 8ee85cb..08ae17c 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -7464,52 +7464,15 @@ jit library is loaded or the JIT compiler will not be activated. for (i = 0; cPaths[i]; i++) { - memset(toybuf, 0, sizeof(toybuf)); if (('/' == cPaths[i][0]) || ('~' == cPaths[i][0])) snprintf(toybuf, sizeof(toybuf), "%s", cPaths[i]); else snprintf(toybuf, sizeof(toybuf), "%s/%s", pwd, cPaths[i]); - if (0 != lstat(toybuf, &st)) - continue; - I("Loading configuration file - %s", toybuf); - status = luaL_loadfile(L, toybuf); - if (status) // If something went wrong, error message is at the top of the stack. - E("Couldn't load file: %s", lua_tostring(L, -1)); - else - { - result = lua_pcall(L, 0, LUA_MULTRET, 0); - if (result) - E("Failed to run script: %s", lua_tostring(L, -1)); - else - { - lua_getglobal(L, "config"); - lua_pushnil(L); - while(lua_next(L, -2) != 0) - { - char *n = (char *) lua_tostring(L, -2); - // Numbers can convert to strings, so check for numbers before checking for strings. - // On the other hand, strings that can be converted to numbers also pass lua_isnumber(). sigh - if (lua_isnumber(L, -1)) - { - float v = lua_tonumber(L, -1); - configs->put(configs, n, &v, sizeof(float)); - } - else if (lua_isstring(L, -1)) - configs->putstr(configs, n, (char *) lua_tostring(L, -1)); - else if (lua_isboolean(L, -1)) - { - int v = lua_toboolean(L, -1); - configs->putint(configs, n, v); - } - else - { - char *v = (char *) lua_tostring(L, -1); - E("Unknown config variable type for %s = %s", n, v); - } - lua_pop(L, 1); - } - } + if (qfile_exist(toybuf)) + { + I("Loading configuration file (maybe) - %s", toybuf); + Lua2hashtbl(toybuf, configs, "config"); } } DEBUG = configs->getint(configs, "debug"); -- cgit v1.1