github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/examples/allocation/tinygo/README.md (about)

     1  ## TinyGo allocation example
     2  
     3  This example shows how to pass strings in and out of a Wasm function defined
     4  in TinyGo, built with `tinygo build -o greet.wasm -scheduler=none -target=wasi greet.go`
     5  
     6  ```bash
     7  $ go run greet.go wazero
     8  wasm >> Hello, wazero!
     9  go >> Hello, wazero!
    10  ```
    11  
    12  Under the covers, [greet.go](testdata/greet.go) does a few things of interest:
    13  * Uses `unsafe.Pointer` to change a Go pointer to a numeric type.
    14  * Uses `reflect.StringHeader` to build back a string from a pointer, len pair.
    15  * Relies on CGO to allocate memory used to pass data from TinyGo to host.
    16  
    17  See https://wazero.io/languages/tinygo/ for more tips.