aboutsummaryrefslogtreecommitdiff
path: root/src/lua_state.c
diff options
context:
space:
mode:
authordacctal <donotcontactmevia@email.invalid>2026-07-26 02:39:45 +0000
committerdacctal <donotcontactmevia@email.invalid>2026-07-26 02:39:45 +0000
commita017a140b912b40a6f61b3d918daa6e7554e65ed (patch)
tree19d2536e6e832856eb93bcb869d97cb1c0259119 /src/lua_state.c
parent184bd50e2ea12b4bf40f4ae1b0d685f0bfa1c995 (diff)
fixed forever loop on lua initialization
Diffstat (limited to 'src/lua_state.c')
-rw-r--r--src/lua_state.c42
1 files changed, 23 insertions, 19 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();
+}