modulepackage
0.3.3
Repository: https://github.com/wapc/wapc-guest-tinygo.git
Documentation: pkg.go.dev
# README
waPC Guest Library for TinyGo
This is the TinyGo implementation of the waPC standard for WebAssembly guest modules. It allows any waPC-compliant WebAssembly host to invoke to procedures inside a TinyGo compiled guest and similarly for the guest to invoke procedures exposed by the host.
Example
The following is a simple example of synchronous, bi-directional procedure calls between a WebAssembly host runtime and the guest module.
package main
import (
wapc "github.com/wapc/wapc-guest-tinygo"
)
func main() {
wapc.RegisterFunctions(wapc.Functions{
"hello": hello,
})
}
func hello(payload []byte) ([]byte, error) {
wapc.HostCall("myBinding", "sample", "hello", []byte("Simon"))
return []byte("Hello"), nil
}
tinygo build -o example/hello.wasm -scheduler=none --no-debug -target=wasi example/hello.go
Considerations
- It is recommended to use the latest versions Go and TinyGo
- Avoid using the
fmt
package as it requiressyscall/js.*
which are not implemented by the waPC host libraries - TinyGo has limited
reflect
package support, thus generated Protobuf code will likely not work without some tweaking (But we have gotten it to work!)
# Packages
No description provided by the author
# Functions
ConsoleLog writes the message the underlying waPC console logger.
HostCall invokes an operation on the host.
RegisterFunction adds a single function by name to the registry.
RegisterFunctions adds functions by name to the registry.