Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/wasmtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ 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", "host_func", |caller: Caller<'_, u32>, param: i32| {
linker.root().instance("host").func_wrap("host_func", |ctx: StoreContextMut<'_, ()>, (param,): (i32,)| {
println!("Got {} from WebAssembly", param);
println!("my host state is: {}", caller.data());
println!("my host state is: {}", ctx.data());
Ok(())
Comment on lines -87 to +90
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example here is for core wasm, not components, so this'll need to stay as it was before. You can add (or link) a different example for components though

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks

})?;

// All wasm objects operate within the context of a "store". Each
Expand Down
6 changes: 6 additions & 0 deletions crates/wasmtime/src/runtime/component/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ impl<T: 'static> LinkerInstance<'_, T> {
/// types that will come from wasm and `Return` is a value coming from the
/// host going back to wasm.
///
/// When defining functions that belong to a specific module instance
/// (rather than the root linker), you must first create the appropriate instance
/// using the [`instance`](LinkerInstance::instance) method and then call `func_wrap`
/// on the returned [`LinkerInstance`]. This is necessary to match the nested
/// instance structure expected by WebAssembly components.
///
/// Additionally the `func` takes a
/// [`StoreContextMut`](crate::StoreContextMut) as its first parameter.
///
Expand Down
Loading