Is it possible to use a resource exported from a world as an parameter for an imported function?
I'm trying to have the guest create a resource and pass in into a function provided by the host.
Here's the wit I currently have:
package webidl:browser;
interface custom-element-export {
resource define-element-base {
connected-callback: func();
}
}
interface custom-element-import {
use custom-element-export.{define-element-base};
define: func(name: string, options: define-element-base);
}
world browser {
export start: func();
export custom-element-export;
import custom-element-import;
}
When generating the bindings with wit-bindgen, it seems to be creating two distinct define-element-base
types, one for the import and another one for the export.
No, it's not possible: https://github.com/WebAssembly/component-model/issues/272
AFAIK, the only way to emulate that kind of callback is to export functions which take e.g. u32
handles which the guest can use as indexes into a table of state objects.
Okay, so no ergonomic way to do this.
I have an alternative idea which only requires imports that I can use instead. Not gonna be as nice, but not too bad either.
Thanks @Joel Dice for the quick response!
Last updated: Dec 23 2024 at 12:05 UTC