diff options
Diffstat (limited to 'src/hooks.c')
| -rw-r--r-- | src/hooks.c | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/src/hooks.c b/src/hooks.c index f47d928..448c7a4 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -31,6 +31,7 @@ bool pkg_exists(str *name) { lua_get_field_type("pkgs", table, &config.init_path, 1); lua_get_field_type(name->data, table, &config.init_path, 2); + lua_pop(L, 2); return true; } @@ -38,22 +39,60 @@ bool pkg_hook_url(package_t *pkg) { lua_get_field_type("pkgs", table, &config.init_path, 1); lua_get_field_type(pkg->name.data, table, &config.init_path, 2); lua_get_field_type("url", string, &config.init_path, 3); + if (!lua_isstring(L, -1)) return false; return true; } str pkg_get_url(package_t *pkg) { - str url = str_new(); - if (!pkg_hook_url(pkg)) return url; - url = mstr(lua_tostring(L, -1)); + str url = {0}; + if (!pkg_hook_url(pkg)) { + lua_pop(L, 3); + return url; + } + const char *url_cstr = lua_tostring(L, -1); + url = mstr(url_cstr); + lua_pop(L, 3); return url; } bool pkg_hook_fetch_sources(package_t *pkg) { + lua_get_field_type("pkgs", table, &config.init_path, 1); + lua_get_field_type(pkg->name.data, table, &config.init_path, 2); + lua_get_field_type("fetcher", table, &config.init_path, 3); + lua_get_field_type("get_source", function, &config.init_path, 4); + lua_pushstring(L, pkg->url.data); + lua_pushstring(L, pkg->version.data); + lua_pushstring(L, pkg->name.data); + lua_run_function("get_source", &config.init_path, 3, 1, 4); + if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) { + lua_pop(L, 4); + return false; + } + lua_pop(L, 4); + return true; +} + +bool pkg_hook_fetch_latest_version(package_t *pkg) { + lua_get_field_type("pkgs", table, &config.init_path, 1); + lua_get_field_type(pkg->name.data, table, &config.init_path, 2); + lua_get_field_type("fetcher", table, &config.init_path, 3); + lua_get_field_type("get_version", function, &config.init_path, 4); + lua_pushstring(L, pkg->url.data); + lua_run_function("get_version", &config.init_path, 1, 1, 4); + if (!lua_isstring(L, -1)) { + lua_pop(L, 4); + return false; + } return true; } -str pkg_hook_fetch_latest_version(package_t *pkg) { - str version = {0}; +str pkg_get_latest_version(package_t *pkg) { + str version = str_new(); + if (!pkg_hook_fetch_latest_version(pkg)) + return version; + if (lua_isstring(L, -1)) + version = mstr(lua_tostring(L, -1)); + lua_pop(L, 4); return version; } @@ -62,6 +101,12 @@ bool pkg_hook_recipe(char *recipe, package_t *pkg) { lua_get_field_type(pkg->name.data, table, &config.init_path, 2); lua_get_field_type("recipe", table, &config.init_path, 3); lua_get_field_type(recipe, function, &config.init_path, 4); + lua_run_function(recipe, &config.init_path, 0, 1, 4); + if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) { + lua_pop(L, 4); + return false; + } + lua_pop(L, 4); return true; } @@ -71,17 +116,21 @@ bool pkg_hook_setup(package_t *pkg) { } bool pkg_hook_build(package_t *pkg) { + pkg_hook_recipe("build", pkg); return true; } bool pkg_hook_install(package_t *pkg) { + pkg_hook_recipe("install", pkg); return true; } bool pkg_hook_remove(package_t *pkg) { + pkg_hook_recipe("remove", pkg); return true; } bool pkg_hook_on_update(package_t *pkg) { + pkg_hook_recipe("on_update", pkg); return true; } |
