Commit Graph

23 Commits

Author SHA1 Message Date
anth64 110b7ffca8 feat(logging)!: add enhanced logging system
BREAKING CHANGE: stk_log() signature changed to require log level

- Add log levels (ERROR, WARN, INFO, DEBUG) with runtime filtering
- Add timestamps (yyyy-mm-dd HH:MM:SS.mmm format)
- Add stk_set_log_output(), stk_set_log_prefix(), stk_set_log_level()
- Platform-specific timestamp: GetLocalTime (Windows), gettimeofday (POSIX)
- Consolidate duplicate platform includes into POSIX common block
- Setting log output to NULL disables logging.

Default: INFO level, "stk" prefix, stdout output. All internal messages
use appropriate severity levels. Single byte flag controls enable/disable.
2026-02-14 16:59:56 +01:00
anth64 26fb19a7f5 feat(core): add flags bitfield system
- Replace stk_initialized with stk_flags bitfield
- Add STK_FLAG_INITIALIZED (0x01) and STK_FLAG_LOGGING_ENABLED (0x02)
- Add stk_set_logging_enabled() and stk_is_logging_enabled() API
- Single byte for all boolean state and settings

Logging enabled by default, packs all flags into one byte for efficiency.
2026-02-14 12:39:13 +01:00
anth64 bcb1795218 fix(core)!: enforce strict C89 compliance
BREAKING CHANGE: Public API now uses unsigned char instead of uint8_t

- Remove stdint.h dependency (C99 feature, not C89, I am a fucking idiot)
- Replace uint8_t with unsigned char throughout codebase
- Affects stk_init() return type and internal functions
- Corrects unintended C99 dependency, restoring intended C89 compliance
2026-02-14 11:41:41 +01:00
anth64 2f4b91c729 refactor(stk): change stk_init() return type to uint8_t
- Change function signature from int to uint8_t for clarity
- Makes return type intent explicit as status flag
2026-01-31 22:40:21 +01:00
anth64 4bd1f00b5b refactor: transition return types to uint8_t and improve error reporting
- Update module load and memory functions to use fixed-width uint8_t
- Implement STK_MOD_REALLOC_FAILURE for granular memory error tracking
- Clean up logging prefixes in stk_poll for consistency
- Update error string helper to support new module error codes
2026-01-31 19:56:36 +01:00
anth64 1e97b69fcd feat: add comprehensive error handling with typed error codes
Add strict error handling for stk initialization and platform operations.
stk_init() now fails fast on critical errors and returns typed error codes
that users can handle programmatically.

Changes:
- Add STK_INIT_* error codes for init failures (memory, tmpdir, watch)
- Add STK_PLATFORM_* error codes for platform operation results
- Check platform_mkdir() and fail if temp directory cannot be created
- Check platform_directory_watch_start() and fail if watch cannot initialize
- Add error_cleanup path in platform_directory_watch_start() to properly
  free resources on critical Windows failures.
- Replace all platform error checks with STK_PLATFORM_OPERATION_SUCCESS
- Log FATAL errors with when critical operations fail
- Add warning logs for non-critical failures

Critical failures now return specific error codes:
- STK_INIT_MEMORY_ERROR: Module memory allocation failed
- STK_INIT_TMPDIR_ERROR: Cannot create temp directory
- STK_INIT_WATCH_ERROR: Cannot start directory watching

Individual module load failures remain non-fatal and are handled logged.
2026-01-31 15:04:20 +01:00
anth64 6567fceaec chore: formalize module loading error codes
* Define Constants: Added STK_MOD_LIBRARY_LOAD_ERROR and STK_MOD_SYMBOL_NOT_FOUND_ERROR to the public header.
* Update module.c: Swapped out the -1 and -2 placeholders for the new named constants in stk_module_load.
2026-01-29 22:53:11 +01:00
anth64 2fbf4ca24a feat(module): implement module initialization status check
* Add STK_MOD_INIT_SUCCESS and STK_MOD_INIT_FAILURE macros to stk.h.
* Update stk_module_load to validate module initialization before finalizing the load.
* Unload library if the init func fails, return error.
2026-01-29 22:40:25 +01:00
anth64 472cb3b163 feat: make module paths and entry points configurable
* Added functions to set mod dir, temp dir name, and module init/shutdown function names.
* Replaced hardcoded string literals with configurable static buffers in module.c.
* Improved string safety by replacing sprintf with strncpy/strncat.
* Updated stk_init local path buffers to handle maximum combined path lengths.
2026-01-25 16:52:52 +01:00
anth64 ac0125274d set default values for mod and tmp dir, removed arguments from stk init 2026-01-25 16:01:51 +01:00
anth64 a3978644af refactor: centralize module identity logic and upgrade lookup
- Move extract_module_id and is_valid_module_file to module.c
- Update is_module_loaded to return module index instead of uint8_t
- Fix platform.c event checks to handle index-based return (>= 0)
- Centralize STK_MODULE_EXT definitions in stk.h
2026-01-18 22:01:54 +01:00
anth64 a290be5dcc feat: implement .tmp directory isolation for safe hot-reload
Add foundation for cross-platform hot-reload system by isolating
loaded modules from source files using a temporary directory.

Changes:
- Add configurable tmp directory parameter to stk_init()
  (defaults to mods/.tmp/ if not specified)
- Copy all modules from mods/ to .tmp/ on initialization
- Load modules exclusively from .tmp/ directory
- Clean up .tmp/ directory on shutdown
- Add cross-platform file operations:
  * platform_mkdir() - create directories
  * platform_copy_file() - copy files
  * platform_remove_file() - delete files
  * platform_remove_dir() - delete directory and contents
- Improve BSD kqueue implementation to detect file overwrites
  (adds individual file watches with NOTE_WRITE)

This isolates the loaded shared libraries from source files,
preventing segfaults when users overwrite mods using cp/copy
operations. The actual reload logic remains unimplemented
(marked as TODO in stk_poll switch cases).
2026-01-18 21:26:17 +01:00
anth64 38469a358f Replace dynamic allocations with fixed-size buffers and add module extension filtering
- Use fixed STK_PATH_MAX and STK_MOD_ID_BUFFER throughout for predictable memory
- Filter by platform-specific extensions (.so/.dll/.dylib) with compile-time length
- Add RELOAD event detection and is_module_loaded() helper
- Maintain feature parity across all platforms
2026-01-17 19:52:42 +01:00
anth64 2820552db8 Add STK_MOD_RELOAD to module event enum 2026-01-17 19:03:22 +01:00
anth64 a7d40929bf 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.
2025-11-07 07:55:44 +01:00
anth64 13604e3f3e Fix Linux inotify event handling and simplify module events
- Simplify to STK_MOD_LOAD/STK_MOD_UNLOAD event types
- Replace IN_CREATE/IN_MODIFY with IN_CLOSE_WRITE to wait for complete writes
- Update watch flags to IN_CLOSE_WRITE | IN_DELETE | IN_MOVED_TO | IN_MOVED_FROM
2025-11-06 20:06:15 +01:00
anth64 ec2aa09596 add stk file event enum and definition for stk poll 2025-11-03 21:44:33 +01:00
anth64 5c621c8367 Init/shutdown working
- stk_init/shutdown do what they are supposed to.
- buffer sizes moved to headers
2025-11-02 18:40:33 +01:00
anth64 7d7f02d1be use a constant for the mod dir buffer size 2025-11-02 12:44:10 +01:00
anth64 a66d9f9357 add mod dir 2025-11-02 12:30:26 +01:00
anth64 df0954ba0d stk module count function, remove stk_ids since handles will be used as "ids" and typedef for stk module functions 2025-10-23 21:36:49 +02:00
anth64 a82fb80a99 prevent c++ name mangling 2025-10-21 00:10:20 +02:00
anth64 079921091f initial code + Makefile 2025-10-08 19:17:18 +02:00