diff options
| author | forever2k38 <forever2k38@forever2k38.net> | 2026-10-21 19:52:27 +0200 |
|---|---|---|
| committer | forever2k38 <forever2k38@forever2k38.net> | 2026-10-21 19:52:27 +0200 |
| commit | 831dacd5cc8073a3053f09cac7bbf715eb4e0b9d (patch) | |
| tree | 6ab8b6d5a27a065e89aba857dbc6fa1dc3bbc4fe /src/package.c | |
| parent | 8a3e05f481dd7425ea859e02806510067fbaaf38 (diff) | |
Diffstat (limited to 'src/package.c')
| -rw-r--r-- | src/package.c | 130 |
1 files changed, 62 insertions, 68 deletions
diff --git a/src/package.c b/src/package.c index 021e8f7..665eeac 100644 --- a/src/package.c +++ b/src/package.c @@ -52,117 +52,111 @@ int pow_extract_package_info(lua_State *L, pow_package *pkg) { lua_getfield(L, -1, "sources"); - if (!lua_istable(L, -1)) { - free(pkg->name); - free(pkg->version); - - pow_log_error("sources is not table or doesn't exist"); - - return 1; - } - - size_t sources_len = lua_objlen(L, -1); + if (lua_istable(L, -1)) { + size_t sources_len = lua_objlen(L, -1); - for (size_t i = 0; i < sources_len; i++) { - lua_pushinteger(L, i + 1); + for (size_t i = 0; i < sources_len; i++) { + lua_pushinteger(L, i + 1); - lua_gettable(L, -2); + lua_gettable(L, -2); - if (lua_type(L, -1) == LUA_TNIL) - break; + if (lua_type(L, -1) == LUA_TNIL) + break; - lua_getfield(L, -1, "path"); + lua_getfield(L, -1, "path"); - pow_package_source *src = malloc(sizeof(pow_package_source)); + pow_package_source *src = malloc(sizeof(pow_package_source)); - if (!src) { - pow_log_error("failed to malloc pow_package_source\n"); + if (!src) { + pow_log_error("failed to malloc pow_package_source\n"); - return 1; - } + return 1; + } - if (!lua_isstring(L, -1)) { - lua_pop(L, 1); + if (!lua_isstring(L, -1)) { + lua_pop(L, 1); - pow_log_error("path is not string"); + pow_log_error("path is not string"); - return 1; - } + return 1; + } - const char *in = strdup(lua_tostring(L, -1)); + const char *in = strdup(lua_tostring(L, -1)); - if (!in) { - pow_log_error("failed to strdup path?"); + if (!in) { + pow_log_error("failed to strdup path?"); - return 1; - } + return 1; + } - src->in = in; + src->in = in; - lua_pop(L, 1); + lua_pop(L, 1); - lua_getfield(L, -1, "out"); + lua_getfield(L, -1, "out"); - if (!lua_isstring(L, -1)) { - lua_pop(L, 1); + if (!lua_isstring(L, -1)) { + lua_pop(L, 1); - pow_log_error("out is not string"); + pow_log_error("out is not string"); - return 1; - } + return 1; + } - const char *out = strdup(lua_tostring(L, -1)); + const char *out = strdup(lua_tostring(L, -1)); - if (!out) { - free(in); + if (!out) { + free(in); - lua_pop(L, 1); + lua_pop(L, 1); - pow_log_error("out strdup failed?"); + pow_log_error("out strdup failed?"); - return 1; - } + return 1; + } - src->out = out; + src->out = out; - lua_pop(L, 1); + lua_pop(L, 1); - lua_getfield(L, -1, "hash"); + lua_getfield(L, -1, "hash"); - if (!lua_isstring(L, -1)) { - free(in); - free(out); + if (!lua_isstring(L, -1)) { + free(in); + free(out); - pow_log_error("hash is not string?"); + pow_log_error("hash is not string?"); - return 1; - } + return 1; + } - const char *hash = strdup(lua_tostring(L, -1)); + const char *hash = strdup(lua_tostring(L, -1)); - if (!hash) { - free(in); - free(out); + if (!hash) { + free(in); + free(out); - pow_log_error("failed to strdup hash"); + pow_log_error("failed to strdup hash"); - return 1; - } + return 1; + } - src->hash = hash; + src->hash = hash; - pkg->source_count++; + pkg->source_count++; - pkg->sources = + pkg->sources = realloc(pkg->sources, pkg->source_count * sizeof(pow_package_source *)); - pkg->sources[pkg->source_count - 1] = src; + pkg->sources[pkg->source_count - 1] = src; + + } lua_pop(L, 1); + lua_pop(L, 1); } lua_pop(L, 1); - lua_pop(L, 1); return 0; } @@ -218,7 +212,7 @@ int pow_package_open(lua_State *L_global, pow_package *pkg, pow_config *cfg, con // push the config object from cfg thread to pkg thread - pow_lua_load(L, cfg, "einfach/base"); + pow_lua_load(L, cfg, pkg->fullname); luaL_loadstring(L, package_buffer); |
