zig-wasm-example

command module
v0.0.0-...-c0b140c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2022 License: MIT Imports: 9 Imported by: 0

README

Zig allocation example

This example shows how to pass strings in and out of a Wasm function defined in Zig, built with zig build.

Ex.

$ go run greet.go wazero
wasm >> Hello, wazero!
go >> Hello, wazero!

Under the covers, main.zig does a few things of interest:

  • Uses @ptrToInt to change a Zig pointer to a numeric type.
  • Uses @intToPtr to build back a string from a pointer, len pair.
  • Relies on Zig not having garbage collector.

Zig code exports "malloc" and "free", which we use for that purpose.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL