# haiku library ## User-defined mechanism requirements - **haiku** requires user to provide his own allocations, assertions and logging mechanisms: * `hk_user_assert_t`: a user-defined assertions (`assert` and an optional user context) * `hk_user_logger_t`: a user-defined logging (`log` and an optional user context) * `hk_user_memory_allocator_t`: a user-defined memory allocations (`alloc`/`free`/`realloc` and an optional user context) - The current C99 implementation **does not** provides a default/fallback mechanism but it can be trivially implemented using the standard library functions. A simple implementation is provided inside the [online sample repository](https://gitlab.xlim.fr/haiku/haiku-samples). - To properly initialize the haiku module, the user call `haiku_module_create` and specify function pointer to appropriate struct members: ```C haiku_module_create(&(hk_module_desc){ .assertion = {.assert_fn = my_sample_assert}, .logger = {.log_fn = my_sample_logger}, .allocator = { .realloc_fn = my_sample_realloc, .alloc_fn = my_sample_alloc, .free_fn = my_sample_free, } }); // [...] haiku_module_destroy(); ``` For the graphics library, the function `haiku_module_create` is wrapped and replaced by a mandatory call to function `hkgfx_module_create` (and equivalent destroy function). ```{eval-rst} .. doxygenstruct:: hk_user_assert_s ``` ```{eval-rst} .. doxygenstruct:: hk_user_logger_s ``` ```{eval-rst} .. doxygenstruct:: hk_user_memory_allocator_s ``` ```{eval-rst} .. doxygenfunction:: haiku_module_create ``` ```{eval-rst} .. doxygenfunction:: haiku_module_destroy ```