emscripten-functions
This crate contains various emscripten system functions (made with rust-native parameter and return value types) that make programming in rust for emscripten targets easier. Functions based on ones from the following emscripten headers are available:
emscripten
console
websocket
(thanks to the GitHub user @Captainfl4me)
Examples
For more examples and tips for emscripten in rust refer to my main project's README.
Run javascript from rust
Using the emscripten_functions::emscripten::run_script
family of functions you can run the javascript you need in your web app.
Example
// The `.escape_unicode()` method makes it safe to pass untrusted user input.
run_script;
Calling JavaScript functions using the val API
Using the emscripten-val
crate, you can make use of emscripten's val API to call JavaScript from the Rust side.
Example
Example taken from the emscripten-val
README:
use ;
use *;
Main loop control
If you need to run a loop function over and over, emscripten has its own main loop managing system.
Using the emscripten_functions::emscripten::set_main_loop
and emscripten_functions::emscripten::set_main_loop_with_arg
functions you can run your rust functions as main loops, with full control over the main loop running parameters.
Example
let mut game_data = GameData
set_main_loop_with_arg;
An SDL game example
An SDL game example that has image handling can be found here.
A websocket sample
A little websocket client application made using emscripten_functions::websocket
can be found here.