lua

package module
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: 6 Imported by: 0

README

Lua

Short project description.


A Lua interpreter, not really a VM. Still a work in progress.

Documentation

Overview

Package lua is the main API package of this application.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	Nil   = nilType(0)
	False = boolType(0)
	True  = boolType(1)
)

Functions

This section is empty.

Types

type Engine

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

func NewEngine

func NewEngine(opts ...Option) Engine

func (Engine) Eval

func (e Engine) Eval(source io.Reader) (Values, error)

Eval evaluates the bytes in the given reader. If an error occurs while parsing, or something strange happens internally, then an error will be returned. However, when Lua's error function is called, the error will be of type Error.

The parsed source will be evaluated as chunk, and all values that the chunk may return are returned as Values.

Example
// this can be every file from os.Open or (afero.Fs).Open, which all implement the
// io.Reader interface
var sourceFile io.Reader = strings.NewReader(`print("Hello, World!")`)
e := NewEngine(
	WithStdout(os.Stdout),
)
_, err := e.Eval(sourceFile)
if err != nil {
	panic(err)
}
Output:

Hello, World!

func (Engine) EvalFile

func (e Engine) EvalFile(path string) (Values, error)

func (Engine) EvalString

func (e Engine) EvalString(source string) (Values, error)
Example
source := `print("Hello, World!")`
e := NewEngine(
	WithStdout(os.Stdout),
)
_, err := e.EvalString(source)
if err != nil {
	panic(err)
}
Output:

Hello, World!

type Error

type Error struct {
	Message string
	Stack   []StackFrame
}

func (Error) Error

func (e Error) Error() string

type Number

type Number float64

type Option

type Option func(*Engine)

func WithScannerType

func WithScannerType(typ ScannerType) 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

func WithWorkingDirectory

func WithWorkingDirectory(dir string) Option

type ScannerType

type ScannerType uint8
const (
	ScannerTypeInMemory ScannerType = iota
)

type StackFrame

type StackFrame struct {
	Name string
}

type String

type String string

type Value

type Value interface {
	// contains filtered or unexported methods
}

type Values

type Values []Value

func (Values) Count

func (v Values) Count() int

func (Values) Get

func (v Values) Get(index int) Value

Directories

Path Synopsis
cmd
lua
internal
ast
tools/analysis/ctxfunc
Package ctxfunc implements an analyzer that checks if a context argument is always the first parameter to a function, and that it is named 'ctx'.
Package ctxfunc implements an analyzer that checks if a context argument is always the first parameter to a function, and that it is named 'ctx'.
tools/analysis/nopanic
Package nopanic implements an analyzer that checks if somewhere in the source, there is a panic.
Package nopanic implements an analyzer that checks if somewhere in the source, there is a panic.

Jump to

Keyboard shortcuts

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