From b25a939e2d8b045c083caf3264c4e5aac1cf88fb Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Tue, 15 Apr 2025 15:51:40 +0200 Subject: Better logging function Now it is possible to provide some data together with the logging function. This is useful for example in C++, where I can now provide an arbitrary callable object as data, and a simple wrapper function that call the callable object as logging function. --- src/utils/dbg_log.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/utils/dbg_log.h') diff --git a/src/utils/dbg_log.h b/src/utils/dbg_log.h index 2467983..e5b3e24 100644 --- a/src/utils/dbg_log.h +++ b/src/utils/dbg_log.h @@ -1,10 +1,11 @@ #include -void (*nissy_log)(const char *); -void write_wrapper(void (*)(const char *), const char *, ...); +void (*nissy_log)(const char *, void *); +void *nissy_log_data; +void write_wrapper(void (*)(const char *, void *), const char *, ...); void -write_wrapper(void (*write)(const char *), const char *str, ...) +write_wrapper(void (*write)(const char *, void *), const char *str, ...) { static const size_t len = 1000; char message[len]; @@ -14,7 +15,7 @@ write_wrapper(void (*write)(const char *), const char *str, ...) vsprintf(message, str, args); va_end(args); - write(message); + write(message, nissy_log_data); } #define LOG(...) if (nissy_log != NULL) write_wrapper(nissy_log, __VA_ARGS__); -- cgit v1.3