From a7d40929bfb70f6cd8791f8d9f1e285121277fb4 Mon Sep 17 00:00:00 2001 From: anth64 Date: Fri, 7 Nov 2025 07:55:44 +0100 Subject: [PATCH] Change shutdown return type and hot reload WIP - stk_shutdown now is a void return type - detect if the module being loaded/unloaded is an existing module. --- include/stk.h | 2 +- src/stk.c | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/stk.h b/include/stk.h index 77c7251..68d0123 100644 --- a/include/stk.h +++ b/include/stk.h @@ -14,7 +14,7 @@ extern "C" { typedef enum { STK_MOD_LOAD, STK_MOD_UNLOAD } stk_module_event_t; int stk_init(const char *mod_dir); -int stk_shutdown(void); +void stk_shutdown(void); size_t stk_module_count(void); size_t stk_poll(void); diff --git a/src/stk.c b/src/stk.c index 74e30e4..d902ec1 100644 --- a/src/stk.c +++ b/src/stk.c @@ -52,12 +52,13 @@ int stk_init(const char *mod_dir) scanned: watch_handle = platform_directory_watch_start(stk_mod_dir); - stk_log(stdout, "[stk] stk v%s initialized! Loaded %zu mods from %s", - STK_VERSION_STRING, module_count, stk_mod_dir); + stk_log(stdout, "[stk] stk v%s initialized! Loaded %zu mod%s from %s/", + STK_VERSION_STRING, module_count, module_count > 1 ? "s" : "", + stk_mod_dir); return 0; } -int stk_shutdown(void) +void stk_shutdown(void) { if (watch_handle) { platform_directory_watch_stop(watch_handle); @@ -67,7 +68,6 @@ int stk_shutdown(void) stk_module_unload_all(); stk_log(stdout, "[stk] stk shutdown"); - return 0; } size_t stk_poll(void) @@ -85,16 +85,24 @@ size_t stk_poll(void) for (i = 0; i < file_count; ++i) { char full_path[PATH_BUFFER_SIZE]; char *module_id; + int existing_index = -1; + size_t j = 0; module_id = file_list[i]; sprintf(full_path, "%s/%s", stk_mod_dir, module_id); + for (j = 0; j < module_count; ++j) { + if (strcmp(module_id, stk_module_ids[j]) != 0) + continue; + + existing_index = j; + break; + } + switch (events[i]) { case STK_MOD_LOAD: - stk_log(stdout, "[stk] STK_MOD_LOAD %s", module_id); break; case STK_MOD_UNLOAD: - stk_log(stdout, "[stk] STK_MOD_UNLOAD %s", module_id); break; } }