Replies: 1 comment 7 replies
-
Hello @Simonl9l thank you for your interest, I will try to answer your questions
The
Yes.
The type of each parameter is a contract between the Host and the Plugin (Guest). So the Host decides what each parameters type is. It's up to the Host devs to provide documentation for the Plugin developers. Unfortunately I can't find a way to make this easier, as wasm functions only support these data types:
We don't have a
One other way is to serialize the whole payload into json (or some other format) and pass it in as one string from the PDK side, and then deserialize it in the Host Function. This way you can pass a complex object between your plugin and host. But, if you prefer having different parameters, then you can use the HostFunction constructor for this purpose: using var hf = new HostFunction(
"my_function",
new[] { ExtismValType.PTR, ExtismValType.PTR, ExtismValType.PTR, ExtismValType.PTR, ExtismValType.I64, ExtismValType.I64 },
new[] { ExtismValType.PTR }, // assuming you return a string
IntPtr.Zero,
(CurrentPlugin plugin, Span<ExtismVal> inputs, Span<ExtismVal> outputs) =>
{
// read inputs
var key1 = plugin.ReadString(inputs[0].v.ptr);
var value1 = plugin.ReadString(inputs[1].v.ptr);
var key2 = plugin.ReadString(inputs[2].v.ptr);
var value2 = plugin.ReadString(inputs[3].v.ptr);
var num1 = inputs[4].v.i64;
var num2 = inputs[5].v.i64;
// TODO: do stuff here
// return a string to the plugin
outputs[0].v.ptr = plugin.WriteString(key1 + value1);
});
You can get the InPtr of a .NET object and pass it in the Host Function. And then you can get it back in the callback through
Support for async functions in wasm is not very good. We will add support for FromMethodAsync as soon as the underlying runtime supports it. Because this must work for all guest languages. I hope this answers your questions. Please let me know if any of the points isn't clear |
Beta Was this translation helpful? Give feedback.
-
Whist that we get that this early days, for comprehensive docs, do you have any examples of how to set up a host function to have multiple arguments?
On poking around the .net sdk, we see this https://github.com/extism/dotnet-sdk/blob/11b9e4933477679f90f7bf11d1b97baa20f324c8/src/Extism.Sdk/HostFunction.cs#L17
It seem that today there is only support for three parameters, via the
FromMethod
static factory functions. It seem that one can't extend that to add additional parameters (on basis that PDK supports it) by replicating/extending this construct with more template arguments, as theToExtismType
helper function is private.However on the basis that for now it supports 3 arguments as
string
's that with such a setup and that the provided callback signature would need to say, specify the type of each aslong
, how does the PDK side of thing know these are in factstring
's?We're kind of inferring this due to the readme per:
On the basis this is known, do each this
long
contain the keyOffset per argument from which one would need toplugin.ReadString(keyOffset)
for each string?How does the PDK side of things know the are in fact supposed to be strings arguments ? Is there an attribute that one need to provide that helps describe this ?
On the basis that all arguments are of the same type, is there a variation of
FromMethod
that can take aparams
(docs) argument as an array of such arguments that can then easily be stuffed in the theinputTypes
/outputTypes
ofHostFunction
?Ideally our use case (in part) we'd need to support some way to represent a set of Key/Value pairs, 4x strings, and two long integers as arguments to the host function.
We guess there could be a set of Host Functions that pass each part, and one to initiate the final request - but this would not be ideal!?
What role does the
userdata
parameter play ?Also per other issues/pr's, it would be good there as an
FromMethodAsync
that encapsulated async/await behaviors and cancellation tokens.We're somewhat fascinated as to what y'alls are putting together here, and are also doing a bunch of .Net/Rust FFI inter-op ourselves so understand some of the challenges, we figure Extism could form a major part of our extensibility model!
Beta Was this translation helpful? Give feedback.
All reactions