Skip to content

Commit

Permalink
For clarity in examples avoid importing/exporting functions of the sa…
Browse files Browse the repository at this point in the history
…me name. (#6211)
  • Loading branch information
ratmice authored Apr 14, 2023
1 parent cc1c14a commit 26f9ce0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/wasmtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn main() -> Result<()> {
let engine = Engine::default();
let wat = r#"
(module
(import "host" "hello" (func $host_hello (param i32)))
(import "host" "host_func" (func $host_hello (param i32)))
(func (export "hello")
i32.const 3
Expand All @@ -84,7 +84,7 @@ fn main() -> Result<()> {
// Create a `Linker` which will be later used to instantiate this module.
// Host functionality is defined by name within the `Linker`.
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!("my host state is: {}", caller.data());
})?;
Expand Down
10 changes: 5 additions & 5 deletions crates/wasmtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
//! let engine = Engine::default();
//! let wat = r#"
//! (module
//! (import "host" "hello" (func $host_hello (param i32)))
//! (import "host" "host_func" (func $host_hello (param i32)))
//!
//! (func (export "hello")
//! i32.const 3
Expand All @@ -47,15 +47,15 @@
//! // `Store` has a type parameter to store host-specific data, which in
//! // this case we're using `4` for.
//! 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!("my host state is: {}", caller.data());
//! });
//!
//! // Instantiation of a module requires specifying its imports and then
//! // afterwards we can fetch exports by name, as well as asserting the
//! // 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")?;
//!
//! // And finally we can call the wasm!
Expand Down Expand Up @@ -146,7 +146,7 @@
//! let engine = Engine::default();
//! let wat = r#"
//! (module
//! (import "host" "hello" (func $host_hello (param i32)))
//! (import "host" "host_func" (func $host_hello (param i32)))
//!
//! (func (export "hello")
//! i32.const 3
Expand All @@ -157,7 +157,7 @@
//!
//! // Create a `Linker` and define our host function in it:
//! 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!("my host state is: {}", caller.data());
//! })?;
Expand Down

0 comments on commit 26f9ce0

Please sign in to comment.