Closed orsinium closed 7 months ago
I'd really like to preserve the ability to infer the call function to use based on the signature, e.g.
modules := funcs.Modules{
"env": {
"hello": helloFunc,
"add": addFunc,
},
}
func helloFunc() {
println("I'm alive!")
}
func addFunc(x, y int32) int32 {
return x+y
}
I'd really like to preserve the ability to infer the call function to use based on the signature, e.g.
Can it be done without reflect
?
What I do is not much different, you just need to wrap it which isn't too verbose:
modules := funcs.Modules{
"env": {
"hello": funcs.F00(helloFunc),
"add": funcs.F21(addFunc),
},
}
Would be good to look at https://github.com/stealthrocket/wazergo for inspiration here?
I think this is a great step in the direction we need, which is being able to be called from guest, and not needing reflection. Now merging, thanks @orsinium
Both wasman and wazero allow to define functions that accept a slice of raw ValueType as input and return a slice of raw ValueType as output. In both cases, the raw representation is the same and uses uint64 as the underlying type. Also, wazero requires all functions in a module to be defined in one go.
To solve code duplication issues and avoid using reflection in wazero, this PR introduces a Modules registry:
The registry is not used in any way in this PR yet but it will be used something like this (which will replace the current
DefineFunc
):