Last active
May 29, 2019 10:07
-
-
Save Hywan/ef13524c7d06a82888452f06de3a3e0f to your computer and use it in GitHub Desktop.
Go Wasm example, memory.go
This file contains hidden or 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
bytes, _ := wasm.ReadBytes("memory.wasm") | |
instance, _ := wasm.NewInstance(bytes) | |
defer instance.Close() | |
// Calls the `return_hello` exported function. | |
// This function returns a pointer to a string. | |
result, _ := instance.Exports["return_hello"]() | |
// Gets the pointer value as an integer. | |
pointer := result.ToI32() | |
// Reads the memory. | |
memory := instance.Memory.Data() | |
fmt.Println(string(memory[pointer : pointer+13])) // Hello, World! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment