wren-go is a port of the Wren scripting language to pure Go using WebAssembly and wagu. Thanks to wagu, wren-go needs almost no dependencies and does not use CGo, making it easier to target web and tinygo targets.
Wren-go also uses a modified version of wren similar to wren-bindings-for-go meant for embedding in non C projects. This means theres no need to preallocate foreign functions and the VM.Exit
function is meant to stop the wren VM in the middle of execution.
go get github.com/crazyinfin8/wren-go
func main() {
cfg := wren.Config{
WriteFn: func(vm wren.VM, message string) { fmt.Print(message) },
}
vm := wren.NewVM(cfg)
vm.Interpret("main", `System.print("Hello from wren!")`)
}
To build, run:
cd path/to/github.com/crazyinfin8/wren-go
go generate
this runs build-wren.go
which:
- first fetches wren (requires git)
- generates the wren amalgamation file
- downloads WASI-libc (it has been buggy to download and run wasi-libc in one go using this script so you may need to run this script twice)
- compiles the wren amalgamation with
src/shim.c
to a webassembly binary using wasi-libc - installs wagu
- generates the IR for wagu
- finally generates Go source code into the
internals
folder.