Skip to content

Instantly share code, notes, and snippets.

@riccardogiorato
Created October 22, 2019 08:10
Show Gist options
  • Save riccardogiorato/2a4982266b06924f43227d0894b220f4 to your computer and use it in GitHub Desktop.
Save riccardogiorato/2a4982266b06924f43227d0894b220f4 to your computer and use it in GitHub Desktop.
// Current prelude for using `wasm_bindgen`, and this'll get smaller over time!
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
// Here we're importing the `alert` function from the browser, using
// `#[wasm_bindgen]` to generate correct wrappers.
#[wasm_bindgen]
extern {
fn alert(s: &str);
}
// Here we're exporting a function called `greet` which will display a greeting
// for `name` through a dialog.
#[wasm_bindgen]
pub fn greet(name: &str) {
let nameFromRust = name.to_owned() +" from Rust!";
alert(&format!("Hello, {}!", nameFromRust));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment