-
So I think this was working before, but not since i update trunk. I have a js function: function showALert(msg) {
alert(msg);
} that i integrate with <script data-trunk src="utils.js"></script> and my rust #[wasm_bindgen]
pub fn greet(name: &str) {
let message = format!("Hello, {}!", name);
show_alert(&message);
} however when i call this function, i get the error log in the browser:
is there a step i'm missing? thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
sorry i also forgot this part of the code: #[wasm_bindgen]
extern "C" {
// Declare the JavaScript function
#[wasm_bindgen(js_name = showAlert)]
fn show_alert(s: &str);
} |
Beta Was this translation helpful? Give feedback.
-
For info this is with trunk version 0.18.3 An easy an better way to do this is to use js snippet so I would turn the file into a module, mark my function with #[wasm_bindgen(module = "/utils.js")]
extern "C" {
fn showALert(msg: &str);
}
#[wasm_bindgen]
pub fn greet(name: &str) {
let message = format!("Hello, {}!", name);
showALert(&message);
} then a |
Beta Was this translation helpful? Give feedback.
For info this is with trunk version 0.18.3
An easy an better way to do this is to use js snippet
so I would turn the file into a module, mark my function with
export
keyword and declare in rustthen a
greet("Sam")
would trigger the browser alert as intended!