Skip to content

Instantly share code, notes, and snippets.

@lachlansneff
Forked from bjfish/lib.rs
Last active January 21, 2019 18:39
Show Gist options
  • Save lachlansneff/af4b86830504ecd44233a729bae14956 to your computer and use it in GitHub Desktop.
Save lachlansneff/af4b86830504ecd44233a729bae14956 to your computer and use it in GitHub Desktop.
Wasmer Wasm Sample App
// Define a function that is imported into the module.
// By default, the "env" namespace is used.
extern "C" {
fn print_str(ptr: *const u8, len: usize);
}
// Define a string that is accessible within the wasm
// linear memory.
static HELLO: &'static str = "Hello, World!";
// Export a function named "hello_wasm". This can be called
// from the embedder!
#[no_mangle]
pub extern fn hello_wasm() {
// Call the function we just imported and pass in
// the offset of our string and its length as parameters.
unsafe {
print_str(HELLO.as_ptr(), HELLO.len());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment