From 3f36ef9b24e2ce978461291d84e293776c41eb66 Mon Sep 17 00:00:00 2001 From: realtradam Date: Wed, 8 Mar 2023 05:16:04 -0500 Subject: added logging system and improved string integration --- include/rodeo.h | 54 +++++++++++++++++++++++++++++++++++++-------------- include/rodeo_types.h | 29 +++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/rodeo.h b/include/rodeo.h index bd156cb..ef9c94f 100644 --- a/include/rodeo.h +++ b/include/rodeo.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,15 @@ #define mrodeo_defer_do(start, end) for( \ int mrodeo_macrovar(_macrovar_) = (start, 0); \ !mrodeo_macrovar(_macrovar_); \ - (mrodeo_macrovar(_macrovar_) += 1), end) \ + (mrodeo_macrovar(_macrovar_) += 1), end) \ + +#define \ +mrodeo_vargs_do(final_arg) \ + va_list vargs; \ + mrodeo_defer_do( \ + va_start(vargs, final_arg), \ + va_end(vargs) \ + ) \ /// --- Math --- @@ -66,7 +75,7 @@ rodeo_frame_end(void); void rodeo_mainloop_run( - rodeo_mainloop_func main_loop_function + rodeo_mainloop_function main_loop_func ); bool @@ -78,7 +87,7 @@ rodeo_set_quit(bool quit); void rodeo_debug_text_draw(uint16_t x, uint16_t y, const char *format, ...); -rodeo_string_p +rodeo_string_t rodeo_renderer_name_get(void); void @@ -92,39 +101,54 @@ rodeo_rectangle_draw( /// --- String --- -rodeo_string_p +rodeo_string_t rodeo_string_create(const char *c_string); void -rodeo_string_destroy(rodeo_string_p self); +rodeo_string_destroy(rodeo_string_t *self); char* -rodeo_string_to_cstr(rodeo_string_p self); +rodeo_string_to_cstr(rodeo_string_t *self); const char* -rodeo_string_to_constcstr(rodeo_string_p self); +rodeo_string_to_constcstr(const rodeo_string_t *self); void rodeo_string_insert( - rodeo_string_p self, - const rodeo_string_p insert, + rodeo_string_t *self, + const rodeo_string_t insert, intptr_t position ); void rodeo_string_append( - rodeo_string_p self, - const rodeo_string_p append + rodeo_string_t *self, + const rodeo_string_t append ); void rodeo_string_prepend( - rodeo_string_p self, - const rodeo_string_p prepend + rodeo_string_t *self, + const rodeo_string_t prepend ); void -rodeo_string_clear(rodeo_string_p self); +rodeo_string_clear(rodeo_string_t *self); void -rodeo_string_set(rodeo_string_p self, char* value); +rodeo_string_set(rodeo_string_t *self, char *value); + +rodeo_string_t +rodeo_string_clone(const rodeo_string_t self); + +rodeo_string_t +rodeo_string_format(const char *format, ...); + +/// --- Log --- + +void +rodeo_log( + rodeo_loglevel_t loglevel, + const char *format, + ... +); diff --git a/include/rodeo_types.h b/include/rodeo_types.h index bdd7ab7..37e87eb 100644 --- a/include/rodeo_types.h +++ b/include/rodeo_types.h @@ -3,6 +3,7 @@ // system #include #include +#include typedef struct { @@ -24,7 +25,7 @@ rodeo_vertex_t; typedef void -(*rodeo_mainloop_func)(void); +(*rodeo_mainloop_function)(void); typedef struct { @@ -35,4 +36,28 @@ typedef struct } rodeo_rectangle_t; -typedef union rodeo_string_t *rodeo_string_p; +/// --- String --- + +// taken from STC library +// must match their layout exactly as it will be cast to it. +// (TODO should write test cases for the string funcs) +typedef char rodeo_string_value_t; +typedef struct { rodeo_string_value_t* data; intptr_t size, cap; } rodeo_string_buffer_t; +typedef union { + struct { rodeo_string_value_t data[sizeof(rodeo_string_buffer_t) - 1]; unsigned char size; } sml; + struct { rodeo_string_value_t* data; size_t size, ncap; } lon; +} rodeo_string_t; + +/// --- Log --- + +typedef enum +{ + rodeo_loglevel_info, + rodeo_loglevel_warning, + rodeo_loglevel_error +} +rodeo_loglevel_t; + +typedef +void +(*rodeo_log_function)(rodeo_string_t text); -- cgit v1.2.3