runtime

package
v0.0.0-...-99b3721 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package runtime is a stack-based register VM to run the bytecode for the parsed lua

Index

Constants

This section is empty.

Variables

View Source
var (
	// Stdin is a file wrapper around stdin so that it can easily be read from.
	Stdin = &File{
		handle:    os.Stdin,
		reader:    bufio.NewReader(os.Stdin),
		Path:      "<stdin>",
		readOnly:  true,
		isstdpipe: true,
	}
	// Stdout is a file wrapper around stdout so that it can easily be written to.
	Stdout = &File{
		handle:    os.Stdout,
		Path:      "<stdout>",
		writeOnly: true,
		isstdpipe: true,
	}
	// Stderr is a file wrapper around stderr to easily write to.
	Stderr = &File{
		handle:    os.Stderr,
		Path:      "<stderr>",
		writeOnly: true,
		isstdpipe: true,
	}
)
View Source
var (
	// WarnEnabled is the flag that will toggle warn messages, it can be toggled with the Warn() function.
	WarnEnabled = false
)

Functions

func PopenCommand

func PopenCommand(arg string) *exec.Cmd

PopenCommand creates a platform independent exec.Cmd.

func ToString

func ToString(val any) string

ToString will format a vm value to a printable string.

Types

type Closure

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

Closure is a lua function encapsulated in the vm.

func (*Closure) String

func (fn *Closure) String() string

type File

type File struct {
	Path   string
	Closed bool
	// contains filtered or unexported fields
}

File is a lua file handle.

func CreateTmpFile

func CreateTmpFile() (*File, error)

CreateTmpFile will create a temporary file.

func OpenFile

func OpenFile(path string, mode int, readOnly, writeOnly bool) (*File, error)

OpenFile will create a new lua file handle with read and write permissions.

func POpen

func POpen(cmdSrc, mode string) (*File, error)

POpen will create a new command and executes it with a filewrapper around it, which makes it easy to read and write from.

func (*File) Close

func (f *File) Close() error

Close will close and flush the file.

func (*File) Read

func (f *File) Read(formats []any) ([]any, error)

func (*File) Seek

func (f *File) Seek(from string, offset int64) (int64, error)

Seek will seek in the file from a point. From can be one of the following values: "set", from the beginning, "cur" the current position, "end" the end of the file. Offset is the offset in bytes.

func (*File) String

func (f *File) String() string

func (*File) Sync

func (f *File) Sync() error

Sync will flush any writes to the file handle.

func (*File) Write

func (f *File) Write(data string) error

type GoFunc

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

GoFunc is a go func usable by the vm.

func Fn

func Fn(name string, fn func(*VM, []any) ([]any, error)) *GoFunc

Fn creates a value that is usable by the vm from a function. This enables exposing a go functionn to the VM.

func (*GoFunc) String

func (fn *GoFunc) String() string

type Interrupt

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

Interrupt is an error type that allows the VM to react to the kind. For instance debug, yield, or exit.

func (*Interrupt) Error

func (interrupt *Interrupt) Error() string

type InterruptKind

type InterruptKind int

InterruptKind distinguishes Interrupts to change the behaviour when an Interrupt was returned from a function call.

const (

	// InterruptExit will interrupt the vm and exit the entire application.
	InterruptExit InterruptKind = iota
	// InterruptYield is only allowed in coroutines and will yield the coroutine to the parent.
	InterruptYield
	// InterruptDebug will interrupt the vm and start a repl in the context where debug was called.
	InterruptDebug
)

type Table

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

Table is a container object in lua that acts both as an array and a map It is used duing runtime but cal also be changed in go code.

func NewTable

func NewTable(arr []any, hash map[any]any) *Table

NewTable will create a new table with default values contained in it. Since lua tables act as both array and map, both can be passed in to set the values.

func (*Table) Get

func (t *Table) Get(key any) (any, error)

Get will return the value for the key. If it is an int it will get it from the array store, otherwise the map. Nil keys are not allowed.

func (*Table) Keys

func (t *Table) Keys() []any

Keys returns the map keys for the map storage used for pairs iteration.

func (*Table) Set

func (t *Table) Set(key, val any) error

Set will set a value at a given key. If the key is an int64, it will place it in array-like storage. Otherwise it will be put in a map. Nil keys are not allowed.

func (*Table) String

func (t *Table) String() string

type Thread

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

Thread is a lua coroutine.

func (*Thread) String

func (t *Thread) String() string

type VM

type VM struct {
	Stack []any
	// contains filtered or unexported fields
}

VM is the interpreter runtime that does everything in memory.

func New

func New(ctx context.Context, env *Table, clargs ...string) *VM

New will create a new vm for evaluating. It will establish the initial stack, setup the environment and globals, and make any extra arguments provided available as the arg value in luaf.

func (*VM) Close

func (vm *VM) Close() error

Close shuts down the vm cleanly and ensures all open files are closed.

func (*VM) Eval

func (vm *VM) Eval(fn *parse.FnProto) ([]any, error)

Eval will take in the parsed fnproto returned from parse and evaluate it.

func (*VM) REPL

func (vm *VM) REPL() error

REPL will start an interactive repl parsing and running lua code.

Directories

Path Synopsis
Package pack allows for serialization and deserialization of data into a string.
Package pack allows for serialization and deserialization of data into a string.
Package pattern is the package that implements lua patterns.
Package pattern is the package that implements lua patterns.

Jump to

Keyboard shortcuts

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