Skip to content

Instantly share code, notes, and snippets.

@Hywan
Last active May 28, 2019 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hywan/82ce861a6e03991d9f23f6a4172eb486 to your computer and use it in GitHub Desktop.
Save Hywan/82ce861a6e03991d9f23f6a4172eb486 to your computer and use it in GitHub Desktop.
Go Wasm example, simple.go
package main
import (
"fmt"
wasm "github.com/wasmerio/go-ext-wasm/wasmer"
)
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