For clarity in examples avoid importing/exporting functions of the same name. (#6211)
This commit is contained in:
@@ -72,7 +72,7 @@ fn main() -> Result<()> {
|
|||||||
let engine = Engine::default();
|
let engine = Engine::default();
|
||||||
let wat = r#"
|
let wat = r#"
|
||||||
(module
|
(module
|
||||||
(import "host" "hello" (func $host_hello (param i32)))
|
(import "host" "host_func" (func $host_hello (param i32)))
|
||||||
|
|
||||||
(func (export "hello")
|
(func (export "hello")
|
||||||
i32.const 3
|
i32.const 3
|
||||||
@@ -84,7 +84,7 @@ fn main() -> Result<()> {
|
|||||||
// Create a `Linker` which will be later used to instantiate this module.
|
// Create a `Linker` which will be later used to instantiate this module.
|
||||||
// Host functionality is defined by name within the `Linker`.
|
// Host functionality is defined by name within the `Linker`.
|
||||||
let mut linker = Linker::new(&engine);
|
let mut linker = Linker::new(&engine);
|
||||||
linker.func_wrap("host", "hello", |caller: Caller<'_, u32>, param: i32| {
|
linker.func_wrap("host", "host_func", |caller: Caller<'_, u32>, param: i32| {
|
||||||
println!("Got {} from WebAssembly", param);
|
println!("Got {} from WebAssembly", param);
|
||||||
println!("my host state is: {}", caller.data());
|
println!("my host state is: {}", caller.data());
|
||||||
})?;
|
})?;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
//! let engine = Engine::default();
|
//! let engine = Engine::default();
|
||||||
//! let wat = r#"
|
//! let wat = r#"
|
||||||
//! (module
|
//! (module
|
||||||
//! (import "host" "hello" (func $host_hello (param i32)))
|
//! (import "host" "host_func" (func $host_hello (param i32)))
|
||||||
//!
|
//!
|
||||||
//! (func (export "hello")
|
//! (func (export "hello")
|
||||||
//! i32.const 3
|
//! i32.const 3
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
//! // `Store` has a type parameter to store host-specific data, which in
|
//! // `Store` has a type parameter to store host-specific data, which in
|
||||||
//! // this case we're using `4` for.
|
//! // this case we're using `4` for.
|
||||||
//! let mut store = Store::new(&engine, 4);
|
//! let mut store = Store::new(&engine, 4);
|
||||||
//! let host_hello = Func::wrap(&mut store, |caller: Caller<'_, u32>, param: i32| {
|
//! let host_func = Func::wrap(&mut store, |caller: Caller<'_, u32>, param: i32| {
|
||||||
//! println!("Got {} from WebAssembly", param);
|
//! println!("Got {} from WebAssembly", param);
|
||||||
//! println!("my host state is: {}", caller.data());
|
//! println!("my host state is: {}", caller.data());
|
||||||
//! });
|
//! });
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
//! // Instantiation of a module requires specifying its imports and then
|
//! // Instantiation of a module requires specifying its imports and then
|
||||||
//! // afterwards we can fetch exports by name, as well as asserting the
|
//! // afterwards we can fetch exports by name, as well as asserting the
|
||||||
//! // type signature of the function with `get_typed_func`.
|
//! // type signature of the function with `get_typed_func`.
|
||||||
//! let instance = Instance::new(&mut store, &module, &[host_hello.into()])?;
|
//! let instance = Instance::new(&mut store, &module, &[host_func.into()])?;
|
||||||
//! let hello = instance.get_typed_func::<(), ()>(&mut store, "hello")?;
|
//! let hello = instance.get_typed_func::<(), ()>(&mut store, "hello")?;
|
||||||
//!
|
//!
|
||||||
//! // And finally we can call the wasm!
|
//! // And finally we can call the wasm!
|
||||||
@@ -146,7 +146,7 @@
|
|||||||
//! let engine = Engine::default();
|
//! let engine = Engine::default();
|
||||||
//! let wat = r#"
|
//! let wat = r#"
|
||||||
//! (module
|
//! (module
|
||||||
//! (import "host" "hello" (func $host_hello (param i32)))
|
//! (import "host" "host_func" (func $host_hello (param i32)))
|
||||||
//!
|
//!
|
||||||
//! (func (export "hello")
|
//! (func (export "hello")
|
||||||
//! i32.const 3
|
//! i32.const 3
|
||||||
@@ -157,7 +157,7 @@
|
|||||||
//!
|
//!
|
||||||
//! // Create a `Linker` and define our host function in it:
|
//! // Create a `Linker` and define our host function in it:
|
||||||
//! let mut linker = Linker::new(&engine);
|
//! let mut linker = Linker::new(&engine);
|
||||||
//! linker.func_wrap("host", "hello", |caller: Caller<'_, u32>, param: i32| {
|
//! linker.func_wrap("host", "host_func", |caller: Caller<'_, u32>, param: i32| {
|
||||||
//! println!("Got {} from WebAssembly", param);
|
//! println!("Got {} from WebAssembly", param);
|
||||||
//! println!("my host state is: {}", caller.data());
|
//! println!("my host state is: {}", caller.data());
|
||||||
//! })?;
|
//! })?;
|
||||||
|
|||||||
Reference in New Issue
Block a user