Skip to content

Instantly share code, notes, and snippets.

Last active May 28, 2019
What would you like to do?
Go Wasm example, simple.go
package main
import (
wasm ""
func main() {
// Reads the WebAssembly module as bytes.
bytes, _ := wasm.ReadBytes("simple.wasm")
// Instantiates the WebAssembly module.
instance, _ := wasm.NewInstance(bytes)
defer instance.Close()
// Gets the `sum` exported function from the WebAssembly instance.
sum := instance.Exports["sum"]
// Calls that exported function with Go standard values. The WebAssembly
// types are inferred and values are casted automatically.
result, _ := sum(5, 37)
fmt.Println(result) // 42!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment