This builds on my last PR and adds support for Host Functions. Currently the limitation is that host functions must have 1 i64 ptr param and 1 i64 ptr result. We enforce this through validation of the typescript interface file.
To enable host functions you just need to declare another interface extism:host/user:
Calling them is a similar process to other PDKs. You need to manage the memory with the Memory object and pass across an offset as the i64 ptr. Using the return value means dereferencing the returned i64 ptr from Memory.
let msg = "Hello from js 1"
let mem = Memory.fromString(msg)
let offset = myHostFunction1(mem.offset)
let response = Memory.find(offset).readString()
if (response != "myHostFunction1: " + msg) {
throw Error(`wrong message came back from myHostFunction1: ${response}`)
}
This builds on my last PR and adds support for Host Functions. Currently the limitation is that host functions must have 1 i64 ptr param and 1 i64 ptr result. We enforce this through validation of the typescript interface file.
To enable host functions you just need to declare another interface
extism:host/user
:These needs to have this signature for now. We will work on making different function arities work next.
To use these you need to use
Host.getFunctions()
:Calling them is a similar process to other PDKs. You need to manage the memory with the
Memory
object and pass across an offset as the i64 ptr. Using the return value means dereferencing the returned i64 ptr from Memory.See example in examples/host_funcs