Created
October 22, 2019 08:10
-
-
Save riccardogiorato/2a4982266b06924f43227d0894b220f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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