2018-03-21 10:03:40 -07:00
|
|
|
#![feature(proc_macro)]
|
|
|
|
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
extern {
|
2018-03-22 16:59:48 -07:00
|
|
|
#[wasm_bindgen(js_namespace = Math)]
|
2018-03-21 10:03:40 -07:00
|
|
|
fn log2(a: f64) -> f64;
|
2018-03-22 16:59:48 -07:00
|
|
|
#[wasm_bindgen(js_namespace = Math)]
|
2018-03-21 10:03:40 -07:00
|
|
|
fn sin(a: f64) -> f64;
|
|
|
|
|
2018-03-22 16:59:48 -07:00
|
|
|
#[wasm_bindgen(js_namespace = console)]
|
2018-03-21 10:03:40 -07:00
|
|
|
fn log(a: &str);
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! println {
|
2018-03-22 16:59:48 -07:00
|
|
|
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
|
2018-03-21 10:03:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn run() {
|
2018-03-22 16:59:48 -07:00
|
|
|
println!("Math.log2(10.0) = {}", log2(10.0));
|
|
|
|
println!("Math.sin(1.2) = {}", sin(1.2));
|
2018-03-21 10:03:40 -07:00
|
|
|
}
|