From be97683fd28bbdd29c3670d6c8cfc7ac3e064b1f Mon Sep 17 00:00:00 2001 From: Ashley Williams Date: Fri, 2 Mar 2018 12:58:28 -0500 Subject: [PATCH] feat(example): add js-hello-world example --- examples/js-hello-world/Cargo.toml | 13 +++++++++++++ examples/js-hello-world/src/lib.rs | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 examples/js-hello-world/Cargo.toml create mode 100644 examples/js-hello-world/src/lib.rs 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)); +}