I follow the instructions from JavaScript . Instead of using node, I call directly from a web browser:
hello_world / index.html
<!DOCTYPE html> <html lang="en"> <head></head> <body> <script src="hello_world.js"></script> <script type='text/javascript'> var hello_world = cwrap('hello_world', 'number', []); var result = hello_world(); console.log("result: ", result); </script> </body> </html>
hello_world / SRC / main.rs
#![feature(link_args)] #[link_args = "-s EXPORTED_FUNCTIONS=['_hello_world']"] extern {} #[no_mangle] pub fn hello_world() -> isize { println!("Hello World!"); 41 + 1 } fn main() {
Command:
cargo build --target asmjs-unknown-emscripten
Error message in Safari:
TypeError: Module ["dynCall_ii"] is not a function. (In 'Module' dynCall_ii '', 'Module ["dynCall_ii"]' is undefined)
Error message in Firefox Nightly:
TypeError: Module.dynCall_ii is not a function More
If I just type the function:
var hello_world = cwrap('hello_world', 'number', []); console.log("function: ", hello_world);
I get (on Firefox Nightly):
Function: asm._hello_world () function
source share