script

package
v1.3.14 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Distributor

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

Distributor continuously scans the stdin for new script code written to it, and broadcasts it to any scripts that are subscribed to it.

func Distribute

func Distribute(reader io.Reader) *Distributor

Distribute starts distributing code lines read from the reader to all subscribes of the distributor.

func (*Distributor) Subscribe

func (distributor *Distributor) Subscribe(script *Script)

Subscribe subscribes a script to all code distributed by the distributor.

type Module

type Module struct {
	Name      string
	Fields    map[string]lua.LValue
	Functions map[string]lua.LGFunction
}

Module represents a module in a script. It may either be set by the Go program directly, or pre-loaded so that the script itself can 'require()' it.

func NewModule

func NewModule(name string) *Module

NewModule returns a new initialised module using the name passed. It has no fields or functions set, but may set to the script.

func (*Module) Field

func (mod *Module) Field(name string, value lua.LValue) *Module

Field adds a field value with a name passed to the module.

func (*Module) Func

func (mod *Module) Func(name string, function lua.LGFunction) *Module

Func adds a function with a name passed to the module.

type Script

type Script struct {
	// ErrorLog is a log.Logger that errors that occur during the interpreting of Lua code. By default, it is
	// set to the package level log variable.
	ErrorLog *log.Logger
	// contains filtered or unexported fields
}

Script is a wrapper around a Lua state. It provides methods to easily add globals and modules to the script from the Go side.

func New

func New() *Script

New returns a new initialised script. It does not run any code yet.

func (*Script) Close

func (script *Script) Close() error

Close closes the script, making it stop processing any code.

func (*Script) Global

func (script *Script) Global(name string) (v Value, ok bool)

Global returns a global value from the script. The global may be either set from the Go side or the script's side.

func (*Script) PreloadModule

func (script *Script) PreloadModule(mod *Module)

PreloadModule pre-loads a script module so that it may be imported in the script using 'require()'. It must be done by the script itself. For the module to be set directly so that the script doesn't have to use 'require()', see SetModule.

func (*Script) RunFile

func (script *Script) RunFile(file string) error

RunFile runs a file containing Lua source code at the path passed.

func (*Script) RunStdin

func (script *Script) RunStdin()

RunStdin starts interpreting the stdin as Lua code. It reports any errors during interpreting to the ErrorLog logger of the script. Multiline code may be encapsulated within double quotes ("") to await execution until the ending double quotes have been written.

func (*Script) RunString

func (script *Script) RunString(lua string) error

RunString runs a string of Lua source code passed. Multiple strings may be ran successively in order to create a continuously running script.

func (*Script) SetGlobal

func (script *Script) SetGlobal(name string, value lua.LValue)

SetGlobal sets a global value to the script, that the script may use during execution.

func (*Script) SetModule

func (script *Script) SetModule(mod *Module)

SetModule sets a script module so that the script can directly access it by the name of the module. No calls to 'require()' need to be made.

type Value

type Value struct {
	lua.LValue
}

Value represents a value that may be fed into a script and taken out of a script. Scripts may operate on these values.

func ValueOf

func ValueOf(value interface{}) Value

ValueOf converts a basic scalar value to a value that may be used to feed into the script. It panics if returned if the value's type is not one of bool, uint8, int8, uint16, int16, uint32, int32, uint64, int64, uint, int, float32, float64, string or nil.

func (Value) Interface

func (value Value) Interface() interface{}

Interface returns the underlying Go value of a Value. Note that numeric types will always be returned as a float64.

Jump to

Keyboard shortcuts

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