From 27f3a69e85d3611547c4bb3e7f114aec0465cf6f Mon Sep 17 00:00:00 2001 From: Sebastian Moser Date: Sun, 1 Dec 2024 11:04:44 +0100 Subject: [PATCH] console_log macro upgrade --- src/platform/wasm/mod.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/platform/wasm/mod.rs b/src/platform/wasm/mod.rs index 2cf6b2f..5d95308 100644 --- a/src/platform/wasm/mod.rs +++ b/src/platform/wasm/mod.rs @@ -14,21 +14,37 @@ use crate::MizeError; use crate::core::item::IntoItemData; + + // console_log macro +// that can be copied into other files for debugging purposes +#[cfg(feature = "wasm-target")] use wasm_bindgen::prelude::*; + +#[cfg(feature = "wasm-target")] #[wasm_bindgen] extern "C" { #[wasm_bindgen(js_namespace = console)] fn log(s: &str); } + +#[cfg(feature = "wasm-target")] macro_rules! console_log { // Note that this is using the `log` function imported above during // `bare_bones` - ($($t:tt)*) => (log(&format_args!($($t)*).to_string())) + ($($t:tt)*) => (unsafe { log(&format_args!($($t)*).to_string())}) +} + +#[cfg(not(feature = "wasm-target"))] +macro_rules! console_log { + // Note that this is using the `log` function imported above during + // `bare_bones` + ($($t:tt)*) => () } //end of console_log macro + // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global // allocator. #[cfg(feature = "wee_alloc")]