aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
index cbbbbe2..100c3c6 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1,6 +1,9 @@
#include "config.h"
#include "log.h"
+#include "paths.h"
+#include "unistd.h"
+#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "stdlib.h"
@@ -126,8 +129,42 @@ int pow_open_config(lua_State *L_global, pow_config *cfg, char *path) {
}
cfg->build_cfg_ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
+ lua_pop(L, 1);
+ }
+
+ if (access("/etc/pow/use.lua", F_OK) != 0) {
+ pow_log_info("use.lua does not exist");
+
+ return 0;
+ }
+
+ lua_State *L_use = lua_newthread(L_global);
+
+ err = luaL_loadfile(L_use, "/etc/pow/use.lua");
+
+ if (err) {
+ pow_log_error("failed to load use.lua");
+
+ return 0;
+ }
+
+ err = lua_pcall(L_use, 0, 1, 0);
+
+ if (err) {
+ pow_log_error("failed to execute use.lua");
+
+ return 0;
}
+ if (!lua_istable(L_use, -1)) {
+ pow_log_error("invalid return value of use.lua");
+
+ return 0;
+ }
+
+ cfg->use_ref = luaL_ref(L_use, LUA_REGISTRYINDEX);
+
return 0;
}