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.
This commit is contained in:
2025-11-07 07:55:44 +01:00
parent 7169dd37b7
commit a7d40929bf
2 changed files with 15 additions and 7 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ extern "C" {
typedef enum { STK_MOD_LOAD, STK_MOD_UNLOAD } stk_module_event_t; typedef enum { STK_MOD_LOAD, STK_MOD_UNLOAD } stk_module_event_t;
int stk_init(const char *mod_dir); int stk_init(const char *mod_dir);
int stk_shutdown(void); void stk_shutdown(void);
size_t stk_module_count(void); size_t stk_module_count(void);
size_t stk_poll(void); size_t stk_poll(void);
+14 -6
View File
@@ -52,12 +52,13 @@ int stk_init(const char *mod_dir)
scanned: scanned:
watch_handle = platform_directory_watch_start(stk_mod_dir); watch_handle = platform_directory_watch_start(stk_mod_dir);
stk_log(stdout, "[stk] stk v%s initialized! Loaded %zu mods from %s", stk_log(stdout, "[stk] stk v%s initialized! Loaded %zu mod%s from %s/",
STK_VERSION_STRING, module_count, stk_mod_dir); STK_VERSION_STRING, module_count, module_count > 1 ? "s" : "",
stk_mod_dir);
return 0; return 0;
} }
int stk_shutdown(void) void stk_shutdown(void)
{ {
if (watch_handle) { if (watch_handle) {
platform_directory_watch_stop(watch_handle); platform_directory_watch_stop(watch_handle);
@@ -67,7 +68,6 @@ int stk_shutdown(void)
stk_module_unload_all(); stk_module_unload_all();
stk_log(stdout, "[stk] stk shutdown"); stk_log(stdout, "[stk] stk shutdown");
return 0;
} }
size_t stk_poll(void) size_t stk_poll(void)
@@ -85,16 +85,24 @@ size_t stk_poll(void)
for (i = 0; i < file_count; ++i) { for (i = 0; i < file_count; ++i) {
char full_path[PATH_BUFFER_SIZE]; char full_path[PATH_BUFFER_SIZE];
char *module_id; char *module_id;
int existing_index = -1;
size_t j = 0;
module_id = file_list[i]; module_id = file_list[i];
sprintf(full_path, "%s/%s", stk_mod_dir, module_id); 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]) { switch (events[i]) {
case STK_MOD_LOAD: case STK_MOD_LOAD:
stk_log(stdout, "[stk] STK_MOD_LOAD %s", module_id);
break; break;
case STK_MOD_UNLOAD: case STK_MOD_UNLOAD:
stk_log(stdout, "[stk] STK_MOD_UNLOAD %s", module_id);
break; break;
} }
} }