From 52c74a1c33ce12b93ec5830f5a6348d9578c7c6e Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 5 Jun 2025 08:37:34 +0200 Subject: Simplify callback business (web version) --- web/logging.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'web/logging.h') diff --git a/web/logging.h b/web/logging.h index 9ed4835..14609a0 100644 --- a/web/logging.h +++ b/web/logging.h @@ -1,11 +1,9 @@ -static int logger_id = -1; +static void (*js_log)(const char *) = nullptr; void log(std::string s) { - if (logger_id == -1) - return; - - callFunction(logger_id, s.c_str()); + if (js_log != nullptr) + js_log(s.c_str()); } void log_wrapper(const char *cstr, void *data) @@ -13,8 +11,12 @@ void log_wrapper(const char *cstr, void *data) log(cstr); } -void set_logger(int id) +/* +To receive a function pointer for JS, we use an int parameter. +This will have to be changed to a 64-bit integer when we move to WASM64. +*/ +void set_logger(int f) { - logger_id = id; + js_log = (void (*)(const char *))f; nissy::set_logger(log_wrapper, NULL); } -- cgit v1.3