script

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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

func (c *Compiled) Clone() *Compiled

Clone creates a new copy of Compiled. Cloned copies are safe for concurrent use by multiple goroutines.

func (*Compiled) Get

func (c *Compiled) Get(name string) *Variable

Get returns a variable identified by the name.

func (*Compiled) GetAll

func (c *Compiled) GetAll() []*Variable

GetAll returns all the variables that are defined by the compiled script.

func (*Compiled) IsDefined

func (c *Compiled) IsDefined(name string) bool

IsDefined returns true if the variable name is defined (has value) before or after the execution.

func (*Compiled) Run

func (c *Compiled) Run() error

Run executes the compiled script in the virtual machine.

func (*Compiled) RunContext

func (c *Compiled) RunContext(ctx context.Context) (err error)

RunContext is like Run but includes a context.

func (*Compiled) Set added in v1.2.0

func (c *Compiled) Set(name string, value interface{}) error

Set replaces the value of a global variable identified by the name. An error will be returned if the name was not defined during compilation.

type Script

type Script struct {
	// contains filtered or unexported fields
}

Script can simplify compilation and execution of embedded scripts.

func New

func New(input []byte) *Script

New creates a Script instance with an input script.

func (*Script) Add

func (s *Script) Add(name string, value interface{}) error

Add adds a new variable or updates an existing variable to the script.

func (*Script) Compile

func (s *Script) Compile() (*Compiled, error)

Compile compiles the script with all the defined variables, and, returns Compiled object.

func (*Script) EnableFileImport added in v1.17.0

func (s *Script) EnableFileImport(enable bool)

EnableFileImport enables or disables module loading from local files. Local file modules are disabled by default.

func (*Script) Remove

func (s *Script) Remove(name string) bool

Remove removes (undefines) an existing variable for the script. It returns false if the variable name is not defined.

func (*Script) Run

func (s *Script) Run() (compiled *Compiled, err error)

Run compiles and runs the scripts. Use returned compiled object to access global variables.

func (*Script) RunContext

func (s *Script) RunContext(ctx context.Context) (compiled *Compiled, err error)

RunContext is like Run but includes a context.

func (*Script) SetImports added in v1.17.0

func (s *Script) SetImports(modules *objects.ModuleMap)

SetImports sets import modules.

func (*Script) SetMaxAllocs added in v1.13.0

func (s *Script) SetMaxAllocs(n int64)

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

func (s *Script) SetMaxConstObjects(n int)

SetMaxConstObjects sets the maximum number of objects in the compiled constants.

type Variable

type Variable struct {
	// contains filtered or unexported fields
}

Variable is a user-defined variable for the script.

func NewVariable

func NewVariable(name string, value interface{}) (*Variable, error)

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

func (v *Variable) Bool() bool

Bool returns bool value of the variable value. It returns 0 if the value is not convertible to bool.

func (*Variable) Bytes

func (v *Variable) Bytes() []byte

Bytes returns a byte slice of the variable value. It returns nil if the value is not convertible to byte slice.

func (*Variable) Char

func (v *Variable) Char() rune

Char returns rune value of the variable value. It returns 0 if the value is not convertible to rune.

func (*Variable) Error

func (v *Variable) Error() error

Error returns an error if the underlying value is error object. If not, this returns nil.

func (*Variable) Float

func (v *Variable) Float() float64

Float returns float64 value of the variable value. It returns 0.0 if the value is not convertible to float64.

func (*Variable) Int

func (v *Variable) Int() int

Int returns int value of the variable value. It returns 0 if the value is not convertible to int.

func (*Variable) Int64

func (v *Variable) Int64() int64

Int64 returns int64 value of the variable value. It returns 0 if the value is not convertible to int64.

func (*Variable) IsUndefined

func (v *Variable) IsUndefined() bool

IsUndefined returns true if the underlying value is undefined.

func (*Variable) Map

func (v *Variable) Map() map[string]interface{}

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) Name

func (v *Variable) Name() string

Name returns the name of the variable.

func (*Variable) Object

func (v *Variable) Object() objects.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

func (v *Variable) String() string

String returns string value of the variable value. It returns 0 if the value is not convertible to string.

func (*Variable) Value

func (v *Variable) Value() interface{}

Value returns an empty interface of the variable value.

func (*Variable) ValueType

func (v *Variable) ValueType() string

ValueType returns the name of the value type.

Jump to

Keyboard shortcuts

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