Documentation ¶
Overview ¶
package script provides a script interpreter for input files and GUI commands.
Index ¶
- Constants
- Variables
- func Contains(tree, search Expr) bool
- func Format(n ast.Node) string
- type BlockStmt
- type Const
- type Expr
- type LValue
- type ScalarFunction
- type ScalarIf
- type TVar
- type VectorFunction
- type VectorIf
- type World
- func (w *World) Compile(src string) (code *BlockStmt, e error)
- func (w *World) CompileExpr(src string) (code Expr, e error)
- func (w World) Const(name string, val interface{}, doc ...string)
- func (w *World) EnterScope()
- func (w *World) Eval(src string) (ret interface{}, err error)
- func (w *World) Exec(src string) error
- func (w *World) ExitScope()
- func (w World) Func(name string, f interface{}, doc ...string)
- func (w World) LValue(name string, v LValue, doc ...string)
- func (w *World) LoadStdlib()
- func (w *World) MustCompile(src string) Expr
- func (w *World) MustCompileExpr(src string) Expr
- func (w *World) MustEval(src string) interface{}
- func (w *World) MustExec(src string)
- func (w World) ROnly(name string, addr interface{}, doc ...string)
- func (w *World) Resolve(identifier string) (e Expr)
- func (w World) TVar(name string, addr interface{}, doc ...string)
- func (w World) Var(name string, addr interface{}, doc ...string)
Constants ¶
const GoExclusiveMethodSuffix = "Go"
Variables ¶
var ( ScalarFunction_t = reflect.TypeOf(dummy_f).In(0) VectorFunction_t = reflect.TypeOf(dummy_f3).In(0) ScalarIf_t = reflect.TypeOf(dummy_scalarif).In(0) VectorIf_t = reflect.TypeOf(dummy_vectorif).In(0) )
common type definitions
var Debug = false // print debug info?
Functions ¶
Types ¶
type Expr ¶
type Expr interface { Eval() interface{} // evaluate and return result (nil for void) Type() reflect.Type // return type, nil for void Child() []Expr Fix() Expr // replace all variables by their current value, except for the time "t". }
an expression can be evaluated
type LValue ¶
type LValue interface { Expr SetValue(interface{}) // assigns a new value }
left-hand value in (single) assign statement
type ScalarFunction ¶
type VectorFunction ¶
type World ¶
type World struct {
// contains filtered or unexported fields
}
World stores an interpreted program's state like declared variables and functions.
func (*World) Compile ¶
compiles source consisting of a number of statements. E.g.:
src = "a = 1; b = sin(x)" code, err := world.Compile(src) code.Eval()
func (*World) CompileExpr ¶
Compiles an expression, which can then be evaluated. E.g.:
expr, err := world.CompileExpr("1+1") expr.Eval() // returns 2
func (*World) EnterScope ¶
func (w *World) EnterScope()
func (*World) Eval ¶
Eval compiles and evaluates src, which must be an expression, and returns the result(s). E.g.:
world.Eval("1+1") // returns 2, nil
func (World) Func ¶
adds a native function to the world. E.g.:
world.Func("sin", math.Sin) world.MustEval("sin(0)") // returns 0
func (World) LValue ¶
adds a special variable to the world. Upon assignment, v's Set() will be called.
func (*World) MustCompile ¶
Like Compile but panics on error
func (*World) MustCompileExpr ¶
CompileExpr with panic on error.
func (World) ROnly ¶
adds a native variable to the world. It cannot be changed from script.
var x = 3.14 world.ROnly("x", &x) world.MustEval("x") // returns 3.14 world.MustExec("x=2") // fails: cannot assign to x