Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Rust example that shows how to import a custom function from JS #71

Open
Zireael07 opened this issue Mar 7, 2020 · 1 comment
Open
Assignees
Labels
enhancement New feature or request

Comments

@Zireael07
Copy link

i.e. something I wrote in index.js, not something that's already available.

@torch2424 torch2424 self-assigned this Mar 9, 2020
@torch2424 torch2424 added the enhancement New feature or request label Mar 9, 2020
@torch2424
Copy link
Owner

@Zireael07 Hello! 😄

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 😂 If, this was what you were reffering to 😄 And I will add this to the docs later if this is what you meant 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants