diff --git a/examples/js-hello-world/Cargo.toml b/examples/js-hello-world/Cargo.toml new file mode 100644 index 0000000..06b256c --- /dev/null +++ b/examples/js-hello-world/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "js-hello-world" +description = "an example rust->wasm crate" +version = "0.1.0" +authors = ["Ashley Williams "] +license = "WTFPL" +repository = "https://github.com/ashleygwilliams/wasm-pack" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +wasm-bindgen = { git = 'https://github.com/alexcrichton/wasm-bindgen' } diff --git a/examples/js-hello-world/src/lib.rs b/examples/js-hello-world/src/lib.rs new file mode 100644 index 0000000..0533cdc --- /dev/null +++ b/examples/js-hello-world/src/lib.rs @@ -0,0 +1,16 @@ +#![feature(proc_macro)] + +extern crate wasm_bindgen; + +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +extern { + fn alert(s: &str); +} + +#[wasm_bindgen] +#[no_mangle] +pub extern fn greet(name: &str) { + alert(&format!("Hello, {}!", name)); +}