Skip to content

Instantly share code, notes, and snippets.

@AugmentedFifth
Created July 14, 2017 22:34
Show Gist options
  • Save AugmentedFifth/233605f49d2eb11cfe4b0eb702d1962f to your computer and use it in GitHub Desktop.
Save AugmentedFifth/233605f49d2eb11cfe4b0eb702d1962f to your computer and use it in GitHub Desktop.
Compiled to WebAssembly and calling into directly from JavaScript
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