Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upClarify #[js_export] target requirements #207
Comments
This comment has been minimized.
This comment has been minimized.
|
It is possible to export functions on emscripten backends, although it isn't really officially supported. For example: fn your_function_to_export() { ... }
fn main() {
js! {
window.your_library = {};
window.your_library.your_function = @{four_function_to_export};
}
stdweb::event_loop();
}and then you can just call it: window.your_library.your_function();Basically, since you can pass a callback into the |
This comment has been minimized.
This comment has been minimized.
ndarilek
commented
Apr 23, 2018
|
Interesting. Does this work similarly if I want to use my library as a
Node module, subbing `globals` for `window`? Do I still need the event
loop in that case?
Are `js_serializable!` and `js_deserializable!` still useful in Emscripten?
Thanks for the help!
|
This comment has been minimized.
This comment has been minimized.
ndarilek
commented
Apr 23, 2018
|
I guess you couldn't just use `globals` under Node since that'd write to
the global namespace on import. That's what I get for dashing out ideas
before caffeine. :)
|
This comment has been minimized.
This comment has been minimized.
For a nodejs module I'd guess you'd want to assign those to
I'm not 100% certain when it's actually really necessary (when I tested it sometimes it was, and sometimes it wasn't.), but basically yes.
Yes they are. I think that anything you can mark as |
ndarilek commentedApr 21, 2018
Saw in the README.md that I could do this, spent some time trying and failing to make it work. When I found the hasher example was doing this, I read in its README that #[js_export] was only supported on wasm32-unknown-unknown.
I need Emscripten. Is #[js_export] not supported there? If not, are there any examples of exporting Rust functions on Emscripten? Not sure if that's even relevant to this crate, but it's documented without any limitations in the main README, so I thought I'd note the possible need for a caveat. :)
Thanks.