-
Notifications
You must be signed in to change notification settings - Fork 59
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
Use node_modules (Node.js) in WASM ? #232
Comments
Here are a few links to docs that should help you out: https://rustwasm.github.io/wasm-bindgen/reference/receiving-js-closures-in-rust.html Does this answer your question? |
I have went thought links and found
or
|
That is a very good help. Thank you ;) I have also one more question. I have just started with WASM RUST and kind of confused about one thing. How do i add to external c this kinda thing from js I know that extern "C" {
fn create(a: u32) -> JsValue;
} but what if i want to export only extern "C" {
// This is completely wrong thing but now
// i can access `client` but how do i get `group` and `create` function from there
#[wasm_bindgen(js_namespace = native)]
// fn client() -> JsValue;
} I would really appreciate if you could help me this one. Thank you. |
@goriunov for that you may be intersted in --
Does that help? |
@alexcrichton I think they're trying to do something like this: #[wasm_bindgen]
extern {
#[wasm_bindgen(js_namespace = "native.client.group")]
fn create(a: u32) -> JsValue;
} But that doesn't seem to work right now. |
@goriunov There might be a better way to do this, but this was the best way that I could come up with: #[wasm_bindgen]
extern {
type Group;
#[wasm_bindgen(method, structural)]
fn create(this: &Group, a: u32) -> JsValue;
}
#[wasm_bindgen]
extern {
type Client;
#[wasm_bindgen(method, structural, getter)]
fn group(this: &Client) -> Group;
}
#[wasm_bindgen]
extern {
type Native;
#[wasm_bindgen(method, structural, getter)]
fn client(this: &Native) -> Client;
}
#[wasm_bindgen]
extern {
static native: Native;
} Here's an example of how to use it: let output = native.client().group().create(0); |
Would be really good to have #[wasm_bindgen]
extern {
#[wasm_bindgen(js_namespace = "native.client.group")]
fn create(a: u32) -> JsValue;
} solution, but second one is alright too :) |
I'm going to close this as I think it's possible to do so today with wasm-bindgen, and I think rustwasm/rfcs#8 and rustwasm/rfcs#6 also help here quite a lot. |
The question is pretty much title.
As example suppose i have
node_modules
which creates a WebSocket will sayws
js is there a way i can pass it to the WASM and use it inside Rust code ?And is there a way to pass function from JS to Rust (callback).
Thank you very much :)
The text was updated successfully, but these errors were encountered: