From 58f6fbe0afb828571463a22737603a037b059909 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Thu, 7 Aug 2025 12:05:51 -0400 Subject: add imports from javascript MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ‘alert’ and ‘console.debug’ --- src/lib.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 7db4248..7129898 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,17 +1,22 @@ use wasm_bindgen::prelude::wasm_bindgen; +#[wasm_bindgen] +extern { + fn alert(s: &str); + + // set the namespace so we can use ‘console.debug’ + #[wasm_bindgen(js_namespace = console)] + fn debug(s: &str); +} + #[wasm_bindgen] pub fn add(left: u32, right: u32) -> u32 { + debug(&format!("adding the numbers {} and {}", + left, right)); left + right } -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } +#[wasm_bindgen] +pub fn test_alert(s: &str) { + alert(s) } -- cgit v1.3