aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordacctal <donotcontactmevia@email.invalid>2026-06-28 08:44:32 +0000
committerdacctal <donotcontactmevia@email.invalid>2026-06-28 08:44:32 +0000
commit1ffeb80f86809931d5d06b231d1dfab44bcd52d4 (patch)
tree89c5c9ea6bdec811e5a32377e6d3c49c8603436b /src
parent2561ad4095ad33127b55ac7627f28e1bcc3e642f (diff)
added on_update for global updates and specific targets
Diffstat (limited to 'src')
-rw-r--r--src/lua_state.c88
-rw-r--r--src/update_all.c1
-rw-r--r--src/update_pkg.c1
3 files changed, 87 insertions, 3 deletions
diff --git a/src/lua_state.c b/src/lua_state.c
index 10820f4..3c53668 100644
--- a/src/lua_state.c
+++ b/src/lua_state.c
@@ -164,6 +164,82 @@ void install_dependencies(lua_State *L) {
}
}
+bool on_update(lua_State *L) {
+ const char* lua_file = "init.lua";
+ lua_getglobal(L, "on_update");
+ if (!lua_isfunction(L, -1)) {
+ if (is_verbose) printf(
+ "%s %s: 'on_update' is not a function.\n",
+ print_warning, lua_file
+ );
+ lua_pop(L, 2);
+ return false;
+ }
+ if (lua_pcall(L, 0, 1, 0) != LUA_OK) {
+ printf(
+ "%s %s: 'on_update' function borked: %s\n",
+ print_error, lua_file, lua_tostring(L, -1)
+ );
+ lua_pop(L, 2);
+ return false;
+ }
+ if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) {
+ printf(
+ "%s %s: 'on_update' failed: %s\n",
+ print_error, lua_file, lua_tostring(L, -1)
+ );
+ lua_pop(L, 2);
+ return false;
+ }
+ lua_pop(L, 2);
+ return true;
+}
+
+bool target_loop_on_update(
+ lua_State *L, const char* lua_file, const char *target
+) {
+ lua_getfield(L, -1, target);
+ if (!lua_istable(L, -1)) {
+ if (is_verbose) printf(
+ "%s %s: 'targets.%s' is not a table.\n",
+ print_warning, lua_file, target
+ );
+ lua_pop(L, 1);
+ if (strcmp(target, "quiet") == 0) {
+ target_loop_on_update(L, lua_file, "default");
+ lua_pop(L, 1);
+ }
+ return false;
+ }
+ lua_getfield(L, -1, "on_update");
+ if (!lua_isfunction(L, -1)) {
+ if (is_verbose) printf(
+ "%s %s: 'targets.%s.on_update' is not a function.\n",
+ print_warning, lua_file, target
+ );
+ lua_pop(L, 3);
+ return false;
+ }
+ if (lua_pcall(L, 0, 1, 0) != LUA_OK) {
+ printf(
+ "%s %s: 'targets.%s.on_update' function borked: %s\n",
+ print_error, lua_file, target, lua_tostring(L, -1)
+ );
+ lua_pop(L, 3);
+ return false;
+ }
+ if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) {
+ printf(
+ "%s %s: 'targets.%s.on_update' failed: %s\n",
+ print_error, lua_file, target, lua_tostring(L, -1)
+ );
+ lua_pop(L, 3);
+ return false;
+ }
+ lua_pop(L, 3);
+ return true;
+}
+
bool target_loop_build(
lua_State *L, const char* lua_file, const char *target
) {
@@ -174,8 +250,10 @@ bool target_loop_build(
print_warning, lua_file, target
);
lua_pop(L, 1);
- if (strcmp(target, "quiet") == 0)
+ if (strcmp(target, "quiet") == 0) {
target_loop_build(L, lua_file, "default");
+ lua_pop(L, 1);
+ }
return false;
}
lua_getfield(L, -1, "dependencies");
@@ -224,8 +302,10 @@ bool target_loop_install(
print_warning, lua_file, target
);
lua_pop(L, 1);
- if (strcmp(target, "quiet") == 0)
+ if (strcmp(target, "quiet") == 0) {
target_loop_install(L, lua_file, "default");
+ lua_pop(L, 1);
+ }
return false;
}
lua_getfield(L, -1, "pre_install");
@@ -304,8 +384,10 @@ bool target_loop_uninstall(lua_State *L, const char *lua_file, const char *targe
print_warning, lua_file, target
);
lua_pop(L, 1);
- if (strcmp(target, "quiet") == 0)
+ if (strcmp(target, "quiet") == 0) {
target_loop_uninstall(L, lua_file, "default");
+ lua_pop(L, 1);
+ }
return false;
}
lua_getfield(L, -1, "uninstall");
diff --git a/src/update_all.c b/src/update_all.c
index 756f98f..4ff750d 100644
--- a/src/update_all.c
+++ b/src/update_all.c
@@ -55,4 +55,5 @@ void update_all(void) {
}
}
closedir(dir_ptr);
+ on_update(get_lua_state());
} \ No newline at end of file
diff --git a/src/update_pkg.c b/src/update_pkg.c
index ea6a20d..cbe7521 100644
--- a/src/update_pkg.c
+++ b/src/update_pkg.c
@@ -40,4 +40,5 @@ void update_pkg(Pkg pkg) {
print_pkgit, green, pkg.name, color_reset
);
install_pkg(pkg);
+ target_loop_on_update(get_lua_state(), "init.lua", pkg.target);
} \ No newline at end of file