Last active
May 28, 2019 13:57
-
-
Save Hywan/82ce861a6e03991d9f23f6a4172eb486 to your computer and use it in GitHub Desktop.
Go Wasm example, simple.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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