From 8a3e05f481dd7425ea859e02806510067fbaaf38 Mon Sep 17 00:00:00 2001 From: forever2k38 Date: Tue, 20 Oct 2026 20:38:32 +0200 Subject: use flags --- src/pow_lua.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/pow_lua.c') 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; } - -- cgit v1.3