diff options
| author | dacctal <donotcontactmevia@email.invalid> | 2026-07-26 02:39:45 +0000 |
|---|---|---|
| committer | dacctal <donotcontactmevia@email.invalid> | 2026-07-26 02:39:45 +0000 |
| commit | a017a140b912b40a6f61b3d918daa6e7554e65ed (patch) | |
| tree | 19d2536e6e832856eb93bcb869d97cb1c0259119 /src | |
| parent | 184bd50e2ea12b4bf40f4ae1b0d685f0bfa1c995 (diff) | |
fixed forever loop on lua initialization
Diffstat (limited to 'src')
| -rw-r--r-- | src/lua_state.c | 42 | ||||
| -rw-r--r-- | src/main.c | 1 | ||||
| -rw-r--r-- | src/state.c | 2 |
3 files changed, 25 insertions, 20 deletions
diff --git a/src/lua_state.c b/src/lua_state.c index 7e9dd18..aa5247f 100644 --- a/src/lua_state.c +++ b/src/lua_state.c @@ -25,6 +25,13 @@ static void lua_path_push(const char *new_path) { lua_pop(L, 1); } +#define HANDLE_LUA_ERROR \ + do { \ + log_error("lua: %s", lua_tostring(L, -1)); \ + lua_pop(L, 1); \ + return false; \ + } while (0) + bool init_lua_state(void) { if (L_is_loaded) return true; @@ -73,18 +80,16 @@ static void setup_base_dirs(void) { } } - config.init_path = str_concat_cstr(&config.dir, "/init.lua"); - config.autogenerated_path = - str_concat_cstr(&config.dir, "/autogenerated.lua"); + config.init_path = str_format( + "%.*s/init.lua", + str_fmt(&config.dir) + ); + config.autogenerated_path = str_format( + "%.*s/autogenerated.lua", + str_fmt(&config.dir) + ); } -#define HANDLE_LUA_ERROR \ - do { \ - log_error("lua: %s", lua_tostring(L, -1)); \ - lua_pop(L, 1); \ - return false; \ - } while (0) - #define lua_get_field_type(name, type, file) \ do { \ lua_getfield(L, -1, name); \ @@ -97,19 +102,16 @@ static void setup_base_dirs(void) { } while (0) static bool load_init_lua(void) { - if (luaL_loadfile(L, config.init_path.data)) - HANDLE_LUA_ERROR; - lua_setglobal(L, "__PkgitUserConfig"); - lua_getglobal(L, "__PkgitUserConfig"); + lua_get_field_type("dirs", table, &config.init_path); #define X(field) \ do { \ lua_get_field_type(#field, string, &config.init_path); \ config.inst_dirs.field = str_adopt((char *)lua_tostring(L, -1)); \ - lua_pop(L, -1); \ + lua_pop(L, 1); \ } while (0) X(prefix); @@ -120,17 +122,15 @@ static bool load_init_lua(void) { #undef X - lua_getfield(L, -1, "prefix"); - return true; } bool init_lua_config(void) { + setup_base_dirs(); + if (!init_lua_state()) return false; - setup_base_dirs(); - if (!load_init_lua()) return false; @@ -144,3 +144,7 @@ void free_lua_state(void) { } L_is_loaded = false; } + +void free_lua_config(void) { + free_lua_state(); +} @@ -33,6 +33,7 @@ int main(int argc, char **argv) { } if (result != CLI_HELP_CALLED) { + init_lua_config(); init_lua_state(); // if (!init_vars()) // return 1; diff --git a/src/state.c b/src/state.c index ec05250..e109628 100644 --- a/src/state.c +++ b/src/state.c @@ -24,4 +24,4 @@ cli_flags_t flags = {0}; user_config_t config = {0}; -install_dirs_t inst_dirs = {0}; +inst_dirs_t inst_dirs = {0}; |
