vm

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(a, b Value) bool

func FloatArg

func FloatArg(name string, n int, args []Value) float64

func FormatTraceback

func FormatTraceback(entries []TracebackEntry) string

func IntArg

func IntArg(name string, n int, args []Value) int64

func IsTruthy

func IsTruthy(v Value) bool

func NumArg

func NumArg(name string, n int, args []Value) (int64, float64, bool, bool)

func OptInt

func OptInt(name string, n int, args []Value, dflt int64) int64

func OptString

func OptString(name string, n int, args []Value, dflt string) string

func PatternGSub

func PatternGSub(
	s, pat string, repl Value, maxN int,
	callFn func(fn Value, args []Value) []Value,
) (string, int)

func PatternHasSpecials

func PatternHasSpecials(pat string) bool

func PromoteToGlobal

func PromoteToGlobal(v *VM, name string)

func RegisterPreload

func RegisterPreload(v *VM, name string, loader func(*VM, []Value) []Value)

func StringArg

func StringArg(name string, n int, args []Value) string

func ToFloat

func ToFloat(v Value) (float64, bool)

func ToInteger

func ToInteger(v Value) (int64, bool)

func ToNumber

func ToNumber(v Value) (intVal int64, floatVal float64, isInt bool, ok bool)

func ToString

func ToString(v Value) string

func ToStringMM

func ToStringMM(v *VM, val Value) string

func TypeName

func TypeName(v Value) string

Types

type CallFrame

type CallFrame struct {
	Closure  *Closure
	IP       int
	Base     int
	Top      int
	NResults int
	Varargs  []Value
	Deferred []*Closure
	// contains filtered or unexported fields
}

type Closure

type Closure struct {
	Proto    *bytecode.InstructionSet
	Upvalues []*Upvalue
}

func ClosureArg

func ClosureArg(name string, n int, args []Value) *Closure

type Coroutine

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

func CoroutineArg

func CoroutineArg(name string, n int, args []Value) *Coroutine

type GMatchIter

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

func NewGMatchIter

func NewGMatchIter(s, pat string, init int) *GMatchIter

func (*GMatchIter) Next

func (g *GMatchIter) Next() []Value

type GoFunc

type GoFunc struct {
	Name string
	Fn   func(vm *VM, args []Value) []Value
}

type LuaError

type LuaError string

func Errorf

func Errorf(format string, args ...any) LuaError

func (LuaError) Error

func (e LuaError) Error() string

type RuntimeError

type RuntimeError struct {
	Value Value
	Msg   string
	Stack []TracebackEntry
}

func (*RuntimeError) Error

func (e *RuntimeError) Error() string

func (*RuntimeError) Message

func (e *RuntimeError) Message() string

func (*RuntimeError) Traceback

func (e *RuntimeError) Traceback() string

type Table

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

func NewTable

func NewTable(arrHint, hashHint int) *Table

func NilOrTableArg

func NilOrTableArg(name string, n int, args []Value) *Table

func TableArg

func TableArg(name string, n int, args []Value) *Table

func TableOrStringArg

func TableOrStringArg(name string, n int, args []Value) (s string, t *Table, isString bool)

func (*Table) Append

func (t *Table) Append(v Value)

func (*Table) EntryCount

func (t *Table) EntryCount() int64

func (*Table) Get

func (t *Table) Get(key Value) Value

func (*Table) Len

func (t *Table) Len() int64

func (*Table) Metatable

func (t *Table) Metatable() *Table

func (*Table) Next

func (t *Table) Next(key Value) (Value, Value)

func (*Table) Set

func (t *Table) Set(key, value Value)

func (*Table) SetMetatable

func (t *Table) SetMetatable(mt *Table)

type Thread

type Thread struct {
	Stack     []Value
	Frames    []*CallFrame
	OpenUpvs  []*Upvalue
	CallMarks []int
}

type TracebackEntry

type TracebackEntry struct {
	Source   string
	Line     int
	Function string
	IsMain   bool
	Elided   int
}

func (TracebackEntry) String

func (e TracebackEntry) String() string

type Upvalue

type Upvalue struct {
	Stack  *[]Value
	Index  int
	Closed Value
}

func (*Upvalue) Get

func (u *Upvalue) Get() Value

func (*Upvalue) Set

func (u *Upvalue) Set(v Value)

type VM

type VM struct {
	Stack   []Value
	Globals *Table
	// contains filtered or unexported fields
}

func New

func New() *VM

func (*VM) AddScriptDir

func (v *VM) AddScriptDir(dir string)

func (*VM) CallFrames

func (v *VM) CallFrames() []*CallFrame

func (*VM) CallValue

func (v *VM) CallValue(fn Value, args []Value, nresults int) []Value

func (*VM) EqualMM

func (v *VM) EqualMM(a, b Value) bool

func (*VM) Run

func (v *VM) Run(main *bytecode.InstructionSet) (err error)

func (*VM) RunMainChunkWithResults

func (v *VM) RunMainChunkWithResults(main *bytecode.InstructionSet) (results []Value, err error)

func (*VM) SafeCall

func (v *VM) SafeCall(fn Value, args []Value) (rs []Value, errVal Value, failed bool)

func (*VM) SafeCallTrace

func (v *VM) SafeCallTrace(fn Value, args []Value) (rs []Value, errVal Value, stack []TracebackEntry, failed bool)

func (*VM) SetGlobal

func (v *VM) SetGlobal(name string, val Value)

func (*VM) Traceback

func (v *VM) Traceback(skip int) []TracebackEntry

type Value

type Value = any

func AnyArg

func AnyArg(name string, n int, args []Value) Value

func PatternFind

func PatternFind(s, pat string, init int) (int, int, []Value, bool)

func PatternMatch

func PatternMatch(s, pat string, init int) []Value

Jump to

Keyboard shortcuts

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