aboutsummaryrefslogtreecommitdiff
path: root/src/pow_lua.c
diff options
context:
space:
mode:
authorforever2k38 <forever2k38@forever2k38.net>2026-10-20 20:38:32 +0200
committerforever2k38 <forever2k38@forever2k38.net>2026-10-20 20:38:32 +0200
commit8a3e05f481dd7425ea859e02806510067fbaaf38 (patch)
tree2a80aacf8ed7d30c718e9f9968a1839f27af29d3 /src/pow_lua.c
parent47edace3c3ea3c9757cf77188d52e8108fb9a03c (diff)
use flags
Diffstat (limited to 'src/pow_lua.c')
-rw-r--r--src/pow_lua.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/pow_lua.c b/src/pow_lua.c
index b3fa69b..1a765b5 100644
--- a/src/pow_lua.c
+++ b/src/pow_lua.c
@@ -36,7 +36,6 @@ int parse_octal_string(const char *str) {
int pow_lua_extract(lua_State *L) {
int r;
- ssize_t size;
struct archive *a;
struct archive_entry *entry;
@@ -300,28 +299,43 @@ int pow_lua_chdir(lua_State *L) {
luaL_Reg libpow[] = {{"chdir", pow_lua_chdir}, {"extract", pow_lua_extract}, {"install", pow_lua_install}, {NULL, NULL}};
-int pow_lua_load(lua_State *L, pow_config *cfg) {
+int pow_lua_load(lua_State *L, pow_config *cfg, char *package_name) {
luaL_newlib(L, libpow);
- lua_createtable(L, 0, 1);
+ lua_rawgeti(cfg->L_cfg, LUA_REGISTRYINDEX, cfg->build_cfg_ref);
+ if (!lua_istable(cfg->L_cfg, -1)) {
+ pow_log_error("failed to initialize lua: config.build is not a table");
+ lua_pop(cfg->L_cfg, 1);
+ return -1;
+ }
+ lua_xmove(cfg->L_cfg, L, 1);
lua_setfield(L, -2, "config");
- lua_rawgeti(cfg->L_cfg, LUA_REGISTRYINDEX, cfg->build_cfg_ref);
+ if (package_name == NULL) {
+ pow_log_error("failed to initialize lua: package_name is NULL");
+ return -1;
+ }
+ lua_rawgeti(cfg->L_cfg, LUA_REGISTRYINDEX, cfg->use_ref);
if (!lua_istable(cfg->L_cfg, -1)) {
- pow_log_error("failed to initialize lua: config.build is not a table");
+ pow_log_error("failed to initialize lua: config.use is not a table");
lua_pop(cfg->L_cfg, 1);
+ return -1;
+ }
- return 1;
+ lua_getfield(cfg->L_cfg, -1, package_name);
+
+ if (lua_isnil(cfg->L_cfg, -1)) {
+ lua_pop(cfg->L_cfg, 1);
+ lua_newtable(cfg->L_cfg);
}
lua_xmove(cfg->L_cfg, L, 1);
-
- lua_setfield(L, -2, "config");
+ lua_pop(cfg->L_cfg, 1);
+ lua_setfield(L, -2, "use");
lua_setglobal(L, "pow");
return 0;
}
-