mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-10 14:48:27 +00:00
Update README.md
This commit is contained in:
@@ -20,7 +20,8 @@ And then:
|
|||||||
```rust
|
```rust
|
||||||
use wasmer::{Store, Module, Instance, Value, imports};
|
use wasmer::{Store, Module, Instance, Value, imports};
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
#[wasm_bindgen]
|
||||||
|
pub extern fn do_add_one_in_wasmer() -> i32 {
|
||||||
let module_wat = r#"
|
let module_wat = r#"
|
||||||
(module
|
(module
|
||||||
(type $t0 (func (param i32) (result i32)))
|
(type $t0 (func (param i32) (result i32)))
|
||||||
@@ -31,16 +32,15 @@ fn main() -> anyhow::Result<()> {
|
|||||||
"#;
|
"#;
|
||||||
|
|
||||||
let store = Store::default();
|
let store = Store::default();
|
||||||
let module = Module::new(&store, &module_wat)?;
|
let module = Module::new(&store, &module_wat).unwrap();
|
||||||
// The module doesn't import anything, so we create an empty import object.
|
// The module doesn't import anything, so we create an empty import object.
|
||||||
let import_object = imports! {};
|
let import_object = imports! {};
|
||||||
let instance = Instance::new(&module, &import_object)?;
|
let instance = Instance::new(&module, &import_object).unwrap();
|
||||||
|
|
||||||
let add_one = instance.exports.get_function("add_one")?;
|
let add_one = instance.exports.get_function("add_one").unwrap();
|
||||||
let result = add_one.call(&[Value::I32(42)])?;
|
let result = add_one.call(&[Value::I32(42)])?;
|
||||||
assert_eq!(result[0], Value::I32(43));
|
assert_eq!(result[0], Value::I32(43));
|
||||||
|
result[0].unwrap_i32()
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user