From 65d8d37b700f74e960336f20f1e3fd0d2851548f Mon Sep 17 00:00:00 2001 From: buffet Date: Mon, 13 Sep 2021 10:25:41 +0000 Subject: [PATCH] Add $XDG_CONFIG_HOME/kiwmi to package path --- kiwmi/luak/luak.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/kiwmi/luak/luak.c b/kiwmi/luak/luak.c index bc21e84..8db884c 100644 --- a/kiwmi/luak/luak.c +++ b/kiwmi/luak/luak.c @@ -240,6 +240,31 @@ luaK_create(struct kiwmi_server *server) } lua_setglobal(L, "kiwmi"); + char *config_path = malloc(PATH_MAX); + if (!config_path) { + wlr_log(WLR_ERROR, "Failed to allocate memory"); + lua_close(L); + free(lua); + return NULL; + } + + const char *config_home = getenv("XDG_CONFIG_HOME"); + if (config_home) { + snprintf(config_path, PATH_MAX, "%s/kiwmi/", config_home); + } else { + snprintf(config_path, PATH_MAX, "%s/.config/kiwmi/", getenv("HOME")); + } + + lua_pushstring(L, config_path); + lua_setglobal(L, "KIWMI_CONFIGDIR"); + free(config_path); + + const char *adjust_package_path = + "package.path = KIWMI_CONFIGDIR .. '/?.lua;' .. package.path\n" + "package.path = KIWMI_CONFIGDIR .. '/?/init.lua;' .. package.path\n"; + + luaL_dostring(L, adjust_package_path); + if (!luaK_ipc_init(server, lua)) { wlr_log(WLR_ERROR, "Failed to initialize IPC"); lua_close(L);