wasm-by-example
wasm-by-example copied to clipboard
Need Rust example that shows how to import a custom function from JS
i.e. something I wrote in index.js, not something that's already available.
@Zireael07 Hello! :smile:
Could you give an example of what you are trying to do? If you mean, import a function that you would be defining I think you can do:
Javascript
window.myCustomJsFunctions = {
myLog: message => console.log(message)
}
Rust
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = myCustomJsFunctions)]
fn myLog(s: &str);
}
myLog("hello, console!");
I referenced this in the wasm-bindgen guide. But there may be a btter way to do this, but I am not sure how to :joy: If, this was what you were reffering to :smile: And I will add this to the docs later if this is what you meant :smile: