gi

package module
v0.0.0-...-8d34ba3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 2 Imported by: 0

README

gi logo

Go GoDoc codecov examples

a Go interpreter that can be used in plugins and debuggers.

status

This is work in progress. See examples for runnable examples using the gi cli. See status for the supported Go language features.

install

go install github.com/emicklei/gi/cmd/gi@latest

Use CLI

gi run .

For development, the following environment variables control the execution and output:

  • GI_TRACE=1 : produce tracing of the virtual machine that executes the statements and expressions.
  • GI_CALL=out.dot : produce a Graphviz DOT file showing the call graph.
  • GI_AST=out.ast : produce the mirror AST text file.

Use as package

run a program

package main

import "github.com/emicklei/gi"

func main() {
	pkg, _ := gi.ParseSource(`package main

import "fmt"

func Hello(name string) int {
	fmt.Println("Hello,", name)
	return 42
}
`)
	answer, err := gi.Call(pkg, "Hello", "3i/Atlas")
}
Credits

The build pipeline uses all programs of Go By Example to check whether they are executable with gi.

© 2025. https://ernestmicklei.com . MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(pkg *Package, funcName string, params ...any) ([]any, error)

Call calls a function named funcName in the given package pkg with the provided parameters values. It returns the results of the function call and an error if any occurred during the call.

func RegisterPackage

func RegisterPackage(pkgPath string, symbols map[string]reflect.Value)

RegisterPackage registers an external package with its symbols for use within gi-executed code.

func Run

func Run(filePath string) error

Run loads, builds, and runs the Go package located at the specified file path. filePath is the file path to a folder that contains a main.go file or any Go source file with a main function.

Types

type Package

type Package = internal.Package

Package represents a Go package loaded and parsed by the gi library.

func ParseSource

func ParseSource(source string) (*Package, error)

ParseSource parses the provided Go source code string and returns a Package representation of it. The source must be valid Go, e.g. main package with a main function. It cannot have external dependencies ; only standard library packages are allowed.

Directories

Path Synopsis
cmd
genstdlib command
gi command
gidebug command
jit command
listpkgs command
treerunner command
examples
api_call command
nestedloop command
pointers command
remoting command
Code generated by cmd/genstdlib/main.go; DO NOT EDIT.
Code generated by cmd/genstdlib/main.go; DO NOT EDIT.

Jump to

Keyboard shortcuts

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