engine

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Break

type Break struct{}

type Clock

type Clock interface {
	Now() time.Time
}

type Engine

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

Engine is an engine that is capable of evaluating Lua code from an io.Reader. The engine keeps track of state, so that multiple calls to Eval will build on the state that the last Eval call produced.

engine.Eval(strings.NewReader(`a=5`))
engine.Eval(strings.NewReader(`print(a)`)) // prints '5'

If an error occurs during parsing or evaluation, that error will be returned. In case of a parse error, the state of the engine will remain unaffected.

func New

func New(opts ...Option) *Engine

New creates a new, ready to use Engine, already applying all given options. By default, the engine uses os.Stdin as stdin, os.Stdout as stdout and os.Stderr as stderr.

func (*Engine) Eval

func (e *Engine) Eval(source io.Reader) ([]value.Value, error)

func (*Engine) EvalFile

func (e *Engine) EvalFile(path string) ([]value.Value, error)

type Error

type Error struct {
	Message value.Value
	Level   value.Value
	Stack   []StackFrame
	// contains filtered or unexported fields
}

Error represents a value originating from Lua's error() function.

func (Error) Error

func (e Error) Error() string

func (Error) Is

func (e Error) Is(target error) bool

func (Error) String

func (e Error) String() string

type Namer

type Namer interface {
	Name() string
}

type Option

type Option func(*Engine)

func WithClock

func WithClock(clock Clock) Option

func WithFs

func WithFs(fs afero.Fs) Option

func WithMaxStackSize

func WithMaxStackSize(maxSize int) Option

func WithStderr

func WithStderr(stderr io.Writer) Option

func WithStdin

func WithStdin(stdin io.Reader) Option

func WithStdout

func WithStdout(stdout io.Writer) Option

type Return

type Return struct {
	Values []value.Value
}

type StackFrame

type StackFrame struct {
	Name string
}

func (StackFrame) String

func (f StackFrame) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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