You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Backstory
I want to use WAI to create a plugin system, where I define the host protocol, implemented by the host, and the plugin protocol, implemented by the plugin. The host will call functions implemented by the plugin, and the plugin can call functions implemented by the host.
I have a working example in this repo, both with wasmer runtime, and wasmtime runtime.
The problem
When I want to use a custom type, like vector3f in this example, I have to define it in both the host protocol, and in the plugin protocol.
move-vec:func(vec: vector3f) -> vector3f
record vector3f{x: float32,y: float32,z: float32,}
This works, but if I want to call the moveY host function from the moveVec plugin function with the same Vector3f type, I quickly run into a problem: it's not the same Vector3f type!
Current solution / workaround
Currently I am solving this by manually converting the host Vector3f type to the plugin one and back, like so:
Needless to say, this is not ideal. Even if the implementation of the conversion could be generated by a macro, I would still need to call ::from() and .into() and worry about which type is which.
Solutions?
This would probably need a separate types.wai file with just the types definitions, then a macro to just import the types from this file, and then finally a way for the import! and export! macros to use the type definitions generated by the previous type macro, instead of generating their own.
Not sure if WAI bindgen supports this, but it would be cool if it did. Any other suggestions on how to (more) easily exchange the same type between host and plugin back and forth are welcome.
The text was updated successfully, but these errors were encountered:
In general the ability to use things from the imports inside the exports and the other way around would be really useful.
For example I want to write a Plug-in system. Usually you'd have an init method that registers all it's functionality to a central registry.
So the init method gets defined in exports so far so good but how am I supposed to get the registry. I can't add it as a parameter because the type doesn't exist in the wai file. If I add an import a method that returns the registry then I can only use types defined in the import wai file so I can't use for example resources defined in the export.
No matter what I do I end up needing to use either things from the import side in the export sice or the other way around.
Backstory
I want to use WAI to create a plugin system, where I define the host protocol, implemented by the host, and the plugin protocol, implemented by the plugin. The host will call functions implemented by the plugin, and the plugin can call functions implemented by the host.
I have a working example in this repo, both with wasmer runtime, and wasmtime runtime.
The problem
When I want to use a custom type, like
vector3f
in this example, I have to define it in both the host protocol, and in the plugin protocol.Host protocol:
Plugin protocol:
This works, but if I want to call the
moveY
host function from themoveVec
plugin function with the sameVector3f
type, I quickly run into a problem: it's not the sameVector3f
type!Current solution / workaround
Currently I am solving this by manually converting the host
Vector3f
type to the plugin one and back, like so:Needless to say, this is not ideal. Even if the implementation of the conversion could be generated by a macro, I would still need to call
::from()
and.into()
and worry about which type is which.Solutions?
This would probably need a separate
types.wai
file with just the types definitions, then a macro to just import the types from this file, and then finally a way for theimport!
andexport!
macros to use the type definitions generated by the previous type macro, instead of generating their own.Not sure if WAI bindgen supports this, but it would be cool if it did. Any other suggestions on how to (more) easily exchange the same type between host and plugin back and forth are welcome.
The text was updated successfully, but these errors were encountered: