diff options
author | onefang | 2021-08-10 17:28:56 +1000 |
---|---|---|
committer | onefang | 2021-08-10 17:28:56 +1000 |
commit | cbe8656511c8aeefa3020cdeec57179fd9ffa61e (patch) | |
tree | 62b342c479887e23813bf11048d57d6dbe3615f5 | |
parent | Switch to toybox xgetcwd() and print the results. (diff) | |
download | opensim-SC-cbe8656511c8aeefa3020cdeec57179fd9ffa61e.zip opensim-SC-cbe8656511c8aeefa3020cdeec57179fd9ffa61e.tar.gz opensim-SC-cbe8656511c8aeefa3020cdeec57179fd9ffa61e.tar.bz2 opensim-SC-cbe8656511c8aeefa3020cdeec57179fd9ffa61e.tar.xz |
Read configs with the newish Lua2hashtbl().
Though this will change again.
Diffstat (limited to '')
-rw-r--r-- | src/sledjchisl/sledjchisl.c | 45 |
1 files changed, 4 insertions, 41 deletions
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. | |||
7464 | 7464 | ||
7465 | for (i = 0; cPaths[i]; i++) | 7465 | for (i = 0; cPaths[i]; i++) |
7466 | { | 7466 | { |
7467 | memset(toybuf, 0, sizeof(toybuf)); | ||
7468 | if (('/' == cPaths[i][0]) || ('~' == cPaths[i][0])) | 7467 | if (('/' == cPaths[i][0]) || ('~' == cPaths[i][0])) |
7469 | snprintf(toybuf, sizeof(toybuf), "%s", cPaths[i]); | 7468 | snprintf(toybuf, sizeof(toybuf), "%s", cPaths[i]); |
7470 | else | 7469 | else |
7471 | snprintf(toybuf, sizeof(toybuf), "%s/%s", pwd, cPaths[i]); | 7470 | snprintf(toybuf, sizeof(toybuf), "%s/%s", pwd, cPaths[i]); |
7472 | if (0 != lstat(toybuf, &st)) | ||
7473 | continue; | ||
7474 | I("Loading configuration file - %s", toybuf); | ||
7475 | status = luaL_loadfile(L, toybuf); | ||
7476 | if (status) // If something went wrong, error message is at the top of the stack. | ||
7477 | E("Couldn't load file: %s", lua_tostring(L, -1)); | ||
7478 | else | ||
7479 | { | ||
7480 | result = lua_pcall(L, 0, LUA_MULTRET, 0); | ||
7481 | if (result) | ||
7482 | E("Failed to run script: %s", lua_tostring(L, -1)); | ||
7483 | else | ||
7484 | { | ||
7485 | lua_getglobal(L, "config"); | ||
7486 | lua_pushnil(L); | ||
7487 | while(lua_next(L, -2) != 0) | ||
7488 | { | ||
7489 | char *n = (char *) lua_tostring(L, -2); | ||
7490 | 7471 | ||
7491 | // Numbers can convert to strings, so check for numbers before checking for strings. | 7472 | if (qfile_exist(toybuf)) |
7492 | // On the other hand, strings that can be converted to numbers also pass lua_isnumber(). sigh | 7473 | { |
7493 | if (lua_isnumber(L, -1)) | 7474 | I("Loading configuration file (maybe) - %s", toybuf); |
7494 | { | 7475 | Lua2hashtbl(toybuf, configs, "config"); |
7495 | float v = lua_tonumber(L, -1); | ||
7496 | configs->put(configs, n, &v, sizeof(float)); | ||
7497 | } | ||
7498 | else if (lua_isstring(L, -1)) | ||
7499 | configs->putstr(configs, n, (char *) lua_tostring(L, -1)); | ||
7500 | else if (lua_isboolean(L, -1)) | ||
7501 | { | ||
7502 | int v = lua_toboolean(L, -1); | ||
7503 | configs->putint(configs, n, v); | ||
7504 | } | ||
7505 | else | ||
7506 | { | ||
7507 | char *v = (char *) lua_tostring(L, -1); | ||
7508 | E("Unknown config variable type for %s = %s", n, v); | ||
7509 | } | ||
7510 | lua_pop(L, 1); | ||
7511 | } | ||
7512 | } | ||
7513 | } | 7476 | } |
7514 | } | 7477 | } |
7515 | DEBUG = configs->getint(configs, "debug"); | 7478 | DEBUG = configs->getint(configs, "debug"); |