Documentation ¶
Index ¶
- type Compiled
- func (c *Compiled) Clone() *Compiled
- func (c *Compiled) Get(name string) *Variable
- func (c *Compiled) GetAll() []*Variable
- func (c *Compiled) IsDefined(name string) bool
- func (c *Compiled) Run() error
- func (c *Compiled) RunContext(ctx context.Context) (err error)
- func (c *Compiled) Set(name string, value interface{}) error
- type Script
- func (s *Script) Add(name string, value interface{}) error
- func (s *Script) Compile() (*Compiled, error)
- func (s *Script) Remove(name string) bool
- func (s *Script) Run() (compiled *Compiled, err error)
- func (s *Script) RunContext(ctx context.Context) (compiled *Compiled, err error)
- func (s *Script) SetBuiltinFunctions(funcs []*objects.BuiltinFunction)
- func (s *Script) SetBuiltinModules(modules map[string]*objects.ImmutableMap)
- func (s *Script) SetMaxAllocs(n int64)
- func (s *Script) SetMaxConstObjects(n int)
- func (s *Script) SetUserModuleLoader(loader compiler.ModuleLoader)
- type Variable
- func (v *Variable) Array() []interface{}
- func (v *Variable) Bool() bool
- func (v *Variable) Bytes() []byte
- func (v *Variable) Char() rune
- func (v *Variable) Error() error
- func (v *Variable) Float() float64
- func (v *Variable) Int() int
- func (v *Variable) Int64() int64
- func (v *Variable) IsUndefined() bool
- func (v *Variable) Map() map[string]interface{}
- func (v *Variable) Name() string
- func (v *Variable) Object() objects.Object
- func (v *Variable) String() string
- func (v *Variable) Value() interface{}
- func (v *Variable) ValueType() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compiled ¶
type Compiled struct {
// contains filtered or unexported fields
}
Compiled is a compiled instance of the user script. Use Script.Compile() to create Compiled object.
func (*Compiled) Clone ¶ added in v1.14.0
Clone creates a new copy of Compiled. Cloned copies are safe for concurrent use by multiple goroutines.
func (*Compiled) IsDefined ¶
IsDefined returns true if the variable name is defined (has value) before or after the execution.
func (*Compiled) RunContext ¶
RunContext is like Run but includes a context.
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
Script can simplify compilation and execution of embedded scripts.
func (*Script) Compile ¶
Compile compiles the script with all the defined variables, and, returns Compiled object.
func (*Script) Remove ¶
Remove removes (undefines) an existing variable for the script. It returns false if the variable name is not defined.
func (*Script) Run ¶
Run compiles and runs the scripts. Use returned compiled object to access global variables.
func (*Script) RunContext ¶
RunContext is like Run but includes a context.
func (*Script) SetBuiltinFunctions ¶ added in v1.10.0
func (s *Script) SetBuiltinFunctions(funcs []*objects.BuiltinFunction)
SetBuiltinFunctions allows to define builtin functions.
func (*Script) SetBuiltinModules ¶ added in v1.10.0
func (s *Script) SetBuiltinModules(modules map[string]*objects.ImmutableMap)
SetBuiltinModules allows to define builtin modules.
func (*Script) SetMaxAllocs ¶ added in v1.13.0
SetMaxAllocs sets the maximum number of objects allocations during the run time. Compiled script will return runtime.ErrObjectAllocLimit error if it exceeds this limit.
func (*Script) SetMaxConstObjects ¶ added in v1.13.0
SetMaxConstObjects sets the maximum number of objects in the compiled constants.
func (*Script) SetUserModuleLoader ¶
func (s *Script) SetUserModuleLoader(loader compiler.ModuleLoader)
SetUserModuleLoader sets the user module loader for the compiler.
type Variable ¶
type Variable struct {
// contains filtered or unexported fields
}
Variable is a user-defined variable for the script.
func NewVariable ¶
NewVariable creates a Variable.
func (*Variable) Array ¶
func (v *Variable) Array() []interface{}
Array returns []interface value of the variable value. It returns 0 if the value is not convertible to []interface.
func (*Variable) Bool ¶
Bool returns bool value of the variable value. It returns 0 if the value is not convertible to bool.
func (*Variable) Bytes ¶
Bytes returns a byte slice of the variable value. It returns nil if the value is not convertible to byte slice.
func (*Variable) Char ¶
Char returns rune value of the variable value. It returns 0 if the value is not convertible to rune.
func (*Variable) Error ¶
Error returns an error if the underlying value is error object. If not, this returns nil.
func (*Variable) Float ¶
Float returns float64 value of the variable value. It returns 0.0 if the value is not convertible to float64.
func (*Variable) Int ¶
Int returns int value of the variable value. It returns 0 if the value is not convertible to int.
func (*Variable) Int64 ¶
Int64 returns int64 value of the variable value. It returns 0 if the value is not convertible to int64.
func (*Variable) IsUndefined ¶
IsUndefined returns true if the underlying value is undefined.
func (*Variable) Map ¶
Map returns map[string]interface{} value of the variable value. It returns 0 if the value is not convertible to map[string]interface{}.
func (*Variable) Object ¶
Object returns an underlying Object of the variable value. Note that returned Object is a copy of an actual Object used in the script.
func (*Variable) String ¶
String returns string value of the variable value. It returns 0 if the value is not convertible to string.