diff options
Diffstat (limited to 'src/hooks.c')
| -rw-r--r-- | src/hooks.c | 107 |
1 files changed, 77 insertions, 30 deletions
diff --git a/src/hooks.c b/src/hooks.c index 20923b7..6053575 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -21,7 +21,8 @@ #include <stdio.h> #include <string.h> -#include "common.h" +#include "bldit.h" +#include "files.h" #include "log.h" #include "lua_state.h" #include "pkg.h" @@ -29,16 +30,18 @@ #include "state.h" 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); + lua_getglobal(L, "__pkgit_user_config"); + lua_get_field_type("pkgs", table, &config.init_path, 2); + lua_get_field_type(name->data, table, &config.init_path, 3); + lua_pop(L, 3); return true; } 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); + lua_getglobal(L, "__pkgit_user_config"); + lua_get_field_type("pkgs", table, &config.init_path, 2); + lua_get_field_type(pkg->name.data, table, &config.init_path, 3); + lua_get_field_type("url", string, &config.init_path, 4); if (!lua_isstring(L, -1)) return false; return true; } @@ -56,33 +59,36 @@ str pkg_get_url(package_t *pkg) { } 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_getglobal(L, "__pkgit_user_config"); + lua_get_field_type("pkgs", table, &config.init_path, 2); + lua_get_field_type(pkg->name.data, table, &config.init_path, 3); + lua_get_field_type("fetcher", table, &config.init_path, 4); + lua_get_field_type("get_source", function, &config.init_path, 5); 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); + lua_run_function("get_source", &config.init_path, 3, 1, 5); if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) { - lua_pop(L, 4); + lua_pop(L, 5); return false; } - lua_pop(L, 4); + lua_pop(L, 5); 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_getglobal(L, "__pkgit_user_config"); + lua_get_field_type("pkgs", table, &config.init_path, 2); + lua_get_field_type(pkg->name.data, table, &config.init_path, 3); + lua_get_field_type("fetcher", table, &config.init_path, 4); + lua_get_field_type("get_version", function, &config.init_path, 5); lua_pushstring(L, pkg->url.data); - lua_run_function("get_version", &config.init_path, 1, 1, 4); + lua_run_function("get_version", &config.init_path, 1, 1, 5); if (!lua_isstring(L, -1)) { - lua_pop(L, 4); + lua_pop(L, 5); return false; } + lua_pop(L, 5); return true; } @@ -95,21 +101,22 @@ str pkg_get_latest_version(package_t *pkg) { str_copy_into(&version, &tmp_version); str_free(&tmp_version); } - lua_pop(L, 4); + lua_pop(L, 5); return version; } bool pkg_hook_recipe(char *recipe, 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("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); + lua_getglobal(L, "__pkgit_user_config"); + lua_get_field_type("pkgs", table, &config.init_path, 2); + lua_get_field_type(pkg->name.data, table, &config.init_path, 3); + lua_get_field_type("recipe", table, &config.init_path, 4); + lua_get_field_type(recipe, function, &config.init_path, 5); + lua_run_function(recipe, &config.init_path, 0, 1, 5); if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) { - lua_pop(L, 4); + lua_pop(L, 5); return false; } - lua_pop(L, 4); + lua_pop(L, 5); return true; } @@ -134,12 +141,52 @@ bool pkg_hook_on_update(package_t *pkg) { } bool config_hook_on_update(void) { - lua_get_field_type("on_update", function, &config.init_path, 1); - lua_run_function("on_update", &config.init_path, 0, 1, 1); + lua_getglobal(L, "__pkgit_user_config"); + lua_get_field_type("on_update", function, &config.init_path, 2); + lua_run_function("on_update", &config.init_path, 0, 1, 2); if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) { + lua_pop(L, 2); + return false; + } + lua_pop(L, 2); + return true; +} + +void bldit_file_set(package_t *pkg) { + pkg->bldit = str_format("%.*s/bldit.lua", str_fmt(&pkg->src)); +} + +bool bldit_file_exists(package_t *pkg) { + if (file_exists(pkg->bldit.data)) return true; + return false; +} + +bool bldit_hook_set(package_t *pkg) { + if (luaL_loadfile(L, pkg->bldit.data) || lua_pcall(L, 0, 1, 0)) { + log_warn("bldit brokie"); lua_pop(L, 1); return false; } + lua_setglobal(L, "__pkgit_bldit_config"); lua_pop(L, 1); return true; } + +bool bldit_hook_recipe(package_t *pkg, const char *recipe) { +// luaL_dofile(L, pkg->bldit.data); +// lua_setglobal(L, "__pkgit_bldit_config"); + lua_getglobal(L, "__pkgit_bldit_config"); + printf("\n%s\n\n", lua_tostring(L, -1)); + log_info("entered bldit config"); + lua_get_field_type("recipe", table, &pkg->bldit, 2); + log_info("entered bldit recipe"); + lua_get_field_type(recipe, table, &pkg->bldit, 3); + log_info("entered bldit recipe function: %s", recipe); + lua_run_function(recipe, &pkg->bldit, 0, 1, 3); + if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) { + lua_pop(L, 3); + return false; + } + lua_pop(L, 3); + return true; +} |
