intrpr

package
v0.0.0-...-2bcc11b Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LangJavaScript = Lang("javascript")
	LangTypeScript = Lang("typescript")
	LangGo         = Lang("go")
	LangTengo      = Lang("tengo")
)

Functions

This section is empty.

Types

type Callable

type Callable func(args ...any) ([]gany.Val, error)

Callable represents a JavaScript function that can be called from Go.

type Lang

type Lang string

type Vm

type Vm interface {
	// LoadScript loads script and do some pre-run preparation,
	// such as transpile, pre-compiling, etc., if the runtime can.
	LoadScript(lang Lang, script string) error

	// SetVal maps golang value into script, it allows script to access go runtime `value` with `name`.
	// Usually `value` is a pointer in the go runtime, that means user can call member functions of `value` from script.
	SetVal(name string, value any) error

	// SetFunc maps golang function into script, it allows script to access go runtime function with `fn`.
	SetFunc(name string, fn any) error

	// Run runs script.
	Run() error

	// GetFunc maps script function to golang runtime, it allows go runtime to access script function.
	GetFunc(name string) (Callable, error)

	// GetVal returns value by variable name, if you want returned value, use `return`.
	GetVal(name string) (gany.Val, error)
}

Vm is script interpreter.

func NewVM

func NewVM(engine string) (Vm, error)

NewVM creates interpreter. It supports Golang script and ECMAScript languages like Javascript, TypeScripts.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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