Skip to content

Instantly share code, notes, and snippets.

@Hywan
Last active May 29, 2019 10:07
Show Gist options
  • Save Hywan/ef13524c7d06a82888452f06de3a3e0f to your computer and use it in GitHub Desktop.
Save Hywan/ef13524c7d06a82888452f06de3a3e0f to your computer and use it in GitHub Desktop.
Go Wasm example, memory.go
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