Stream: wit-bindgen

Topic: Function pointers in wit


view this post on Zulip Paul Hummer (May 20 2025 at 23:42):

I'm looking to use wit/wit-bindgen/wasmtime to build what amounts to a plugin system. There are exported functions that we'll call from our wasmtime environment. Those functions will schedule callbacks whose flow control is handled by the host environment.

The problem that I'm running into is that those symbols are private, and so they are inaccessible from the component (rightfully so). But I don't see a mechanism for specifying a function pointer as a parameter type to host function that would register the callback. Am I missing something, or is there missing functionality?

view this post on Zulip Lann Martin (May 21 2025 at 18:13):

You can probably implement this with a host-defined resource type

view this post on Zulip Lann Martin (May 21 2025 at 18:13):

This example might help: https://docs.rs/wasmtime/33.0.0/wasmtime/component/bindgen_examples/_4_imported_resources/index.html

view this post on Zulip Lann Martin (May 21 2025 at 18:14):

The host would track the function pointer in the resource state (MyLogger in the example)


Last updated: Dec 06 2025 at 07:03 UTC