Created
December 4, 2020 09:18
-
-
Save syrusakbary/3a3470c4ec1ce26c36044dd6ef43a626 to your computer and use it in GitHub Desktop.
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
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