github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/examples/allocation/zig/README.md (about) 1 ## Zig allocation example 2 3 This example shows how to pass strings in and out of a Wasm function defined in 4 Zig, built with `zig build`. 5 6 ```bash 7 $ go run greet.go wazero 8 wasm >> Hello, wazero! 9 go >> Hello, wazero! 10 ``` 11 12 [greet.zig](testdata/greet.zig) does a few things of interest: 13 * Uses `@ptrToInt` to change a Zig pointer to a numeric type 14 * Uses `[*]u8` as an argument to take a pointer and slices it to build back a 15 string 16 17 The Zig code exports "malloc" and "free", which we use for that purpose. 18 19 ### Notes 20 21 This example uses `@panic()` rather than `unreachable` to handle errors 22 since `unreachable` emits a call to panic only in `Debug` and `ReleaseSafe` 23 mode. In `ReleaseFast` and `ReleaseSmall` mode, it would lead into undefined 24 behavior.