Skip to content

Instantly share code, notes, and snippets.

@syrusakbary
Created December 4, 2020 09:18
Show Gist options
  • Save syrusakbary/3a3470c4ec1ce26c36044dd6ef43a626 to your computer and use it in GitHub Desktop.
Save syrusakbary/3a3470c4ec1ce26c36044dd6ef43a626 to your computer and use it in GitHub Desktop.
use wasmer::{Store, Module, Instance, Value, imports};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let module_wat = r#"
(module
(type $t0 (func (param i32) (result i32)))
(func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32)
get_local $p0
i32.const 1
i32.add))
"#;
let store = Store::default();
let module = Module::new(&store, &module_wat);
let import_object = imports! {};
let instance = Instance::new(module, &import_object)?;
let add_one = instance.exports.get_function("add_one")?;
let result = add_one.call([Value::I32(42)])?;
assert_eq!(result[0], Value::I32(43));
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment