mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-12 05:18:43 +00:00
Fix JS sample code by adding "&mut store"
`Instance::new` and `.call` need `&mut store` as first argument in order to compile.
This commit is contained in:
@@ -368,6 +368,9 @@
|
|||||||
//! to compile it with [`wasm-pack`] and [`wasm-bindgen`]:
|
//! to compile it with [`wasm-pack`] and [`wasm-bindgen`]:
|
||||||
//!
|
//!
|
||||||
//! ```ignore
|
//! ```ignore
|
||||||
|
//! use wasm_bindgen::prelude::*;
|
||||||
|
//! use wasmer::{imports, Instance, Module, Store, Value};
|
||||||
|
//!
|
||||||
//! #[wasm_bindgen]
|
//! #[wasm_bindgen]
|
||||||
//! pub extern fn do_add_one_in_wasmer() -> i32 {
|
//! pub extern fn do_add_one_in_wasmer() -> i32 {
|
||||||
//! let module_wat = r#"
|
//! let module_wat = r#"
|
||||||
@@ -382,10 +385,10 @@
|
|||||||
//! let module = Module::new(&store, &module_wat).unwrap();
|
//! 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).unwrap();
|
//! let instance = Instance::new(&mut store, &module, &import_object).unwrap();
|
||||||
//!
|
//!
|
||||||
//! let add_one = instance.exports.get_function("add_one").unwrap();
|
//! let add_one = instance.exports.get_function("add_one").unwrap();
|
||||||
//! let result = add_one.call(&[Value::I32(42)]).unwrap();
|
//! let result = add_one.call(&mut store, &[Value::I32(42)]).unwrap();
|
||||||
//! assert_eq!(result[0], Value::I32(43));
|
//! assert_eq!(result[0], Value::I32(43));
|
||||||
//!
|
//!
|
||||||
//! result[0].unwrap_i32()
|
//! result[0].unwrap_i32()
|
||||||
|
|||||||
Reference in New Issue
Block a user