Skip to content

CrazyInfin8/wren-go

Repository files navigation

wren-go

Wren scripting language in pure Go

Go Reference GoReportCard Wren

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.

Installation

go get github.com/crazyinfin8/wren-go

Usage

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!")`)
}

Building wren-go

To build, run:

cd path/to/github.com/crazyinfin8/wren-go
go generate

this runs build-wren.go which:

  1. first fetches wren (requires git)
  2. generates the wren amalgamation file
  3. 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)
  4. compiles the wren amalgamation with src/shim.c to a webassembly binary using wasi-libc
  5. installs wagu
  6. generates the IR for wagu
  7. finally generates Go source code into the internals folder.