Created
July 14, 2017 22:34
-
-
Save AugmentedFifth/233605f49d2eb11cfe4b0eb702d1962f to your computer and use it in GitHub Desktop.
Compiled to WebAssembly and calling into directly from JavaScript
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
extern crate libc; | |
#[macro_use] | |
extern crate lazy_static; | |
use std::sync::Mutex; | |
use std::vec::Vec; | |
lazy_static! { | |
static ref BUFFER: Mutex<Vec<i32>> = Mutex::new(Vec::with_capacity(8)); | |
} | |
fn main() { | |
println!("Rust-based WebAssembly loaded successfully."); | |
} | |
#[no_mangle] | |
pub fn push(val: i32) { | |
BUFFER.lock().unwrap().push(val) | |
} | |
#[no_mangle] | |
pub fn pop() -> i32 { | |
BUFFER.lock().unwrap().pop().unwrap() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment