Documentation
¶
Overview ¶
Package lua is a dependency-free Lua 5.1 implementation written in Go.
Index ¶
- Variables
- func LoadScript(source, name string, globals map[string]Value) (*Script, []Value, error)
- type Error
- type Function
- type Instruction
- type Kind
- type LocalVariableInfo
- type NativeFunction
- type Prototype
- type Script
- type State
- func (s *State) Call(function Value, args ...Value) ([]Value, error)
- func (s *State) CallInto(function Value, args, results []Value) (int, error)
- func (s *State) CallNumber2(function Value, a, b float64) (float64, error)
- func (s *State) DoString(source string) ([]Value, error)
- func (s *State) GetGlobal(name string) Value
- func (s *State) Globals() *Table
- func (s *State) Load(source, name string) (Value, error)
- func (s *State) SetGlobal(name string, value Value)
- func (s *State) String() string
- type Table
- func (t *Table) ForEach(fn func(Value, Value) bool)
- func (t *Table) Get(key Value) Value
- func (t *Table) GetString(name string) Value
- func (t *Table) Len() int
- func (t *Table) Metatable() *Table
- func (t *Table) Next(previous Value) (Value, Value, bool)
- func (t *Table) Set(key, value Value) error
- func (t *Table) SetMetatable(meta *Table)
- func (t *Table) SetString(name string, value Value)
- type Thread
- type UpvalueDescriptor
- type Value
- func Bool(v bool) Value
- func FunctionValue(v *Function) Value
- func Native(fn NativeFunction) Value
- func NativeBinary(fn func(float64, float64) float64) Value
- func Number(v float64) Value
- func String(v string) Value
- func TableValue(v *Table) Value
- func ThreadValue(v *Thread) Value
- func Userdata(v any) Value
- func UserdataWithMetatable(v any, meta *Table) Value
- func (v Value) Bool() bool
- func (v Value) Function() *Function
- func (v Value) Interface() any
- func (v Value) Kind() Kind
- func (v Value) Number() float64
- func (v Value) Repr() string
- func (v Value) StringValue() string
- func (v Value) Table() *Table
- func (v Value) Thread() *Thread
- func (v Value) Truthy() bool
- func (v Value) TypeName() string
- func (v Value) UserdataValue() any
Constants ¶
This section is empty.
Variables ¶
var False = Value{/* contains filtered or unexported fields */}
var Nil = Value{}
var True = Value{/* contains filtered or unexported fields */}
Functions ¶
Types ¶
type Instruction ¶
type Instruction uint32
Instruction is a compact fixed-width register instruction. ABC operands cover hot arithmetic/table operations; Bx is used for constants and jumps.
type Kind ¶
type Kind uint8
Kind is deliberately byte-sized: Value is copied in every VM instruction.
type LocalVariableInfo ¶
type Prototype ¶
type Prototype struct {
Source string
DefinedLine int
LastDefinedLine int
EndLine int
Code []Instruction
Constants []Value
Children []*Prototype
Upvalues []UpvalueDescriptor
UpvalueNames []string
RegisterNames map[int]string
LocalVariables []LocalVariableInfo
Lines []int
LiveRegisters []uint8
Parameters uint8
MaxRegisters uint8
Vararg bool
UsesDots bool
Captured bool
Fast bool
NumericPure bool
NumericCode []Instruction
NumericRegisters uint8
NumericFormula *numericFormula
FieldCaches []fieldCache
ExtraConstants map[int]int
ErrorContexts map[int][]string
}
type Script ¶
Script owns a persistent VM and an optional module table returned by its chunk. Calls are serialized because a State intentionally reuses stacks.
type State ¶
func (*State) Call ¶
Call invokes a Lua function with any number of arguments and returns an owned slice of every result. This generality has a cost: dispatch can route to the general VM, which stores a callee's varargs slice directly in its frame, so Go's escape analysis must (correctly) treat args as escaping for every call through this function, not just vararg ones — escape analysis is a static property of the function body, not of a particular call's runtime arguments. The variadic argument slice and the returned result slice therefore both allocate. For a hot loop, use CallInto (reused argument/result buffers, zero allocation) or CallNumber2 (a specialized allocation-free path for two-argument numeric functions) instead.
func (*State) CallInto ¶
CallInto invokes a Lua function without allocating a result slice. It returns the total result count and copies as many values as fit in results. Callers that need every result should provide sufficient destination space.
func (*State) CallNumber2 ¶
CallNumber2 is the allocation-free embedding path for the common numeric binary-function case measured by the embedding benchmark.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is a hybrid array/hash table. Dense positive integer keys avoid hashing; strings have a dedicated map because they dominate object fields. The generic map handles the uncommon boolean/reference/non-dense keys.
func (*Table) ForEach ¶
ForEach visits live entries. Iteration order is intentionally unspecified, matching Lua's next/pairs contract.
func (*Table) SetMetatable ¶
type Thread ¶
type Thread struct {
// contains filtered or unexported fields
}
Thread is a Lua coroutine. A suspended coroutine retains its ordinary VM call stack in a parked Go goroutine; resume and yield rendezvous directly, so no C stack, cgo shim, or copied continuation is involved.
type UpvalueDescriptor ¶
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is a compact tagged pair. bits stores numbers, booleans, or string length; ptr stores reference objects or string data. Keeping every Lua value to three machine words materially reduces register and table traffic.
func FunctionValue ¶
func Native ¶
func Native(fn NativeFunction) Value
func NativeBinary ¶
NativeBinary registers the allocation-free typed path for a Go numeric callback called from Lua.
func TableValue ¶
func ThreadValue ¶
func UserdataWithMetatable ¶
func (Value) StringValue ¶
func (Value) UserdataValue ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Command examples demonstrates embedding the native Go Lua plugin both directly (github.com/oarkflow/interpreter/plugins/lua) and through the host interpreter's SPL layer.
|
Command examples demonstrates embedding the native Go Lua plugin both directly (github.com/oarkflow/interpreter/plugins/lua) and through the host interpreter's SPL layer. |