Documentation ¶
Index ¶
- Constants
- Variables
- func BinaryArithmeticError(op string, x, y Value) error
- func Call(t *Thread, f Value, args []Value, next Cont) error
- func ErrorIsUnexpectedEOF(err error) bool
- func HasMarshalPrefix(bs []byte) bool
- func IntLen(t *Thread, v Value) (int64, error)
- func Lt(t *Thread, x, y Value) (bool, error)
- func MarshalConst(w io.Writer, c Value, budget uint64) (used uint64, err error)
- func Metacall(t *Thread, obj Value, method string, args []Value, next Cont) (error, bool)
- func RawEqual(x, y Value) (bool, bool)
- func SetIndex(t *Thread, coll Value, idx Value, val Value) error
- func SolemnlyDeclareCompliance(flags ComplianceFlags, fs ...*GoFunction)
- func ToFloat(v Value) (float64, bool)
- func ToInt(v Value) (int64, bool)
- func ToIntNoString(v Value) (int64, bool)
- func ToNumberValue(v Value) (Value, NumberType)
- func Truth(v Value) bool
- func UnaryArithmeticError(op string, x Value) error
- type Callable
- type Cell
- type Closure
- type Code
- type ComplianceFlags
- type Cont
- type ContextTerminationError
- type DebugHookFlags
- type DebugHooks
- type DebugInfo
- type Error
- type GCPolicy
- type GoCont
- func (c *GoCont) Arg(n int) Value
- func (c *GoCont) Args() []Value
- func (c *GoCont) BoolArg(n int) (bool, error)
- func (c *GoCont) CallableArg(n int) (Callable, error)
- func (c *GoCont) Check1Arg() error
- func (c *GoCont) CheckNArgs(n int) error
- func (c *GoCont) ClosureArg(n int) (*Closure, error)
- func (c *GoCont) DebugInfo() *DebugInfo
- func (c *GoCont) Etc() []Value
- func (c *GoCont) FloatArg(n int) (float64, error)
- func (c *GoCont) IntArg(n int) (int64, error)
- func (c *GoCont) NArgs() int
- func (c *GoCont) Next() Cont
- func (c *GoCont) Parent() Cont
- func (c *GoCont) Push(r *Runtime, v Value)
- func (c *GoCont) PushEtc(r *Runtime, etc []Value)
- func (c *GoCont) PushingNext(r *Runtime, vals ...Value) Cont
- func (c *GoCont) PushingNext1(r *Runtime, val Value) Cont
- func (c *GoCont) RunInThread(t *Thread) (next Cont, err error)
- func (c *GoCont) StringArg(n int) (string, error)
- func (c *GoCont) TableArg(n int) (*Table, error)
- func (c *GoCont) ThreadArg(n int) (*Thread, error)
- func (c *GoCont) UserDataArg(n int) (*UserData, error)
- type GoFunction
- type GoFunctionFunc
- type LightUserData
- type LogWarner
- type LuaCont
- type Metatabler
- type NumberType
- type ResourceReleaser
- type Runtime
- func (m *Runtime) CheckRequiredFlags(flags ComplianceFlags) error
- func (r *Runtime) Close(err *error)
- func (r *Runtime) CompileAndLoadLuaChunk(name string, source []byte, env Value, scannerOptions ...scanner.Option) (*Closure, error)
- func (r *Runtime) CompileAndLoadLuaChunkOrExp(name string, source []byte, env Value, scannerOptions ...scanner.Option) (*Closure, error)
- func (r *Runtime) CompileLuaChunk(name string, source []byte, scannerOptions ...scanner.Option) (*code.Unit, uint64, error)
- func (r *Runtime) CompileLuaChunkOrExp(name string, source []byte, scannerOptions ...scanner.Option) (unit *code.Unit, sz uint64, err error)
- func (m *Runtime) Due() bool
- func (m *Runtime) GCPolicy() GCPolicy
- func (r *Runtime) GlobalEnv() *Table
- func (m *Runtime) HardLimits() RuntimeResources
- func (m *Runtime) KillContext()
- func (m *Runtime) LinearRequire(cpuFactor uint64, amt uint64)
- func (m *Runtime) LinearUnused(cpuFactor uint64) uint64
- func (r *Runtime) LoadFromSourceOrCode(name string, source []byte, mode string, env Value, stripComment bool) (*Closure, error)
- func (r *Runtime) LoadLuaUnit(unit *code.Unit, env Value) *Closure
- func (r *Runtime) MainThread() *Thread
- func (r *Runtime) Metatable(v Value) Value
- func (r *Runtime) NewUserDataValue(iface interface{}, meta *Table) Value
- func (m *Runtime) Parent() RuntimeContext
- func (r *Runtime) ParseLuaChunk(name string, source []byte, scannerOptions ...scanner.Option) (stat *ast.BlockStat, statSize uint64, err error)
- func (r *Runtime) ParseLuaExp(name string, source []byte, scannerOptions ...scanner.Option) (stat *ast.BlockStat, statSize uint64, err error)
- func (m *Runtime) PopContext() RuntimeContext
- func (r *Runtime) ProcessIoError(c Cont, ioErr error) (Cont, error)
- func (r *Runtime) Push(c Cont, vals ...Value)
- func (r *Runtime) Push1(c Cont, v Value)
- func (m *Runtime) PushContext(ctx RuntimeContextDef)
- func (r *Runtime) PushIoError(c Cont, ioErr error) error
- func (r *Runtime) RawMetatable(v Value) *Table
- func (r *Runtime) RefactorCodeConsts(c *Code) *Code
- func (r *Runtime) Registry(key Value) Value
- func (m *Runtime) ReleaseArrSize(sz uintptr, n int)
- func (m *Runtime) ReleaseBytes(n int)
- func (m *Runtime) ReleaseMem(memAmount uint64)
- func (m *Runtime) ReleaseSize(sz uintptr)
- func (m *Runtime) RequireArrSize(sz uintptr, n int) (mem uint64)
- func (m *Runtime) RequireBytes(n int) (mem uint64)
- func (m *Runtime) RequireCPU(cpuAmount uint64)
- func (m *Runtime) RequireMem(memAmount uint64)
- func (m *Runtime) RequireSize(sz uintptr) (mem uint64)
- func (m *Runtime) RequiredFlags() ComplianceFlags
- func (m *Runtime) RuntimeContext() RuntimeContext
- func (r *Runtime) SetEnv(t *Table, name string, v Value)
- func (r *Runtime) SetEnvGoFunc(t *Table, name string, f GoFunctionFunc, nArgs int, hasEtc bool) *GoFunction
- func (r *Runtime) SetRawMetatable(v Value, meta *Table)
- func (r *Runtime) SetRegistry(k, v Value)
- func (m *Runtime) SetStopLevel(stopLevel StopLevel)
- func (r *Runtime) SetStringMeta(meta *Table)
- func (r *Runtime) SetTable(t *Table, k, v Value)
- func (r *Runtime) SetTableCheck(t *Table, k, v Value) error
- func (r *Runtime) SetWarner(warner Warner)
- func (m *Runtime) SoftLimits() RuntimeResources
- func (m *Runtime) Status() RuntimeContextStatus
- func (m *Runtime) TerminateContext(format string, args ...interface{})
- func (r *Runtime) Traceback(pfx string, c Cont) string
- func (m *Runtime) UnusedCPU() uint64
- func (m *Runtime) UnusedMem() uint64
- func (m *Runtime) UsedResources() RuntimeResources
- func (r *Runtime) Warn(msgs ...string)
- type RuntimeContext
- type RuntimeContextDef
- type RuntimeContextStatus
- type RuntimeOption
- type RuntimeResources
- type StopLevel
- type SyntaxError
- type Table
- func (t *Table) Clone() luagc.Value
- func (t *Table) Get(k Value) Value
- func (t *Table) Key() luagc.Key
- func (t *Table) Len() int64
- func (t *Table) Metatable() *Table
- func (t *Table) Next(k Value) (next Value, val Value, ok bool)
- func (t *Table) Reset(k, v Value) (wasSet bool)
- func (t *Table) Set(k, v Value) uint64
- func (t *Table) SetMetatable(m *Table)
- type Termination
- func (c *Termination) DebugInfo() *DebugInfo
- func (c *Termination) Etc() []Value
- func (c *Termination) Get(n int) Value
- func (c *Termination) Next() Cont
- func (c *Termination) Parent() Cont
- func (c *Termination) Push(r *Runtime, v Value)
- func (c *Termination) PushEtc(r *Runtime, etc []Value)
- func (c *Termination) Reset()
- func (c *Termination) RunInThread(t *Thread) (Cont, error)
- type Thread
- func (t *Thread) CallContext(def RuntimeContextDef, f func() error) (ctx RuntimeContext, err error)
- func (m Thread) CheckRequiredFlags(flags ComplianceFlags) error
- func (t *Thread) Close(caller *Thread) (bool, error)
- func (t *Thread) CollectGarbage()
- func (t *Thread) CurrentCont() Cont
- func (m Thread) Due() bool
- func (m Thread) GCPolicy() GCPolicy
- func (m Thread) HardLimits() RuntimeResources
- func (t *Thread) IsMain() bool
- func (m Thread) KillContext()
- func (m Thread) LinearRequire(cpuFactor uint64, amt uint64)
- func (m Thread) LinearUnused(cpuFactor uint64) uint64
- func (m Thread) Parent() RuntimeContext
- func (m Thread) PopContext() RuntimeContext
- func (m Thread) PushContext(ctx RuntimeContextDef)
- func (m Thread) ReleaseArrSize(sz uintptr, n int)
- func (m Thread) ReleaseBytes(n int)
- func (m Thread) ReleaseMem(memAmount uint64)
- func (m Thread) ReleaseSize(sz uintptr)
- func (m Thread) RequireArrSize(sz uintptr, n int) (mem uint64)
- func (m Thread) RequireBytes(n int) (mem uint64)
- func (m Thread) RequireCPU(cpuAmount uint64)
- func (m Thread) RequireMem(memAmount uint64)
- func (m Thread) RequireSize(sz uintptr) (mem uint64)
- func (m Thread) RequiredFlags() ComplianceFlags
- func (t *Thread) Resume(caller *Thread, args []Value) ([]Value, error)
- func (t *Thread) RunContinuation(c Cont) (err error)
- func (m Thread) RuntimeContext() RuntimeContext
- func (m Thread) SetStopLevel(stopLevel StopLevel)
- func (m Thread) SoftLimits() RuntimeResources
- func (t *Thread) Start(c Callable)
- func (t *Thread) Status() ThreadStatus
- func (m Thread) TerminateContext(format string, args ...interface{})
- func (m Thread) UnusedCPU() uint64
- func (m Thread) UnusedMem() uint64
- func (m Thread) UsedResources() RuntimeResources
- func (t *Thread) Yield(args []Value) ([]Value, error)
- type ThreadStatus
- type UserData
- type UserDataResourceReleaser
- type Value
- func Add(x, y Value) (Value, bool)
- func ArrayValue(a []Value) Value
- func AsValue(i interface{}) Value
- func BoolValue(b bool) Value
- func Call1(t *Thread, f Value, args ...Value) (Value, error)
- func CodeValue(c *Code) Value
- func Concat(t *Thread, x, y Value) (Value, error)
- func ContValue(c Cont) Value
- func Div(x, y Value) (Value, bool)
- func ErrorValue(err error) Value
- func FloatValue(f float64) Value
- func FunctionValue(c Callable) Value
- func Idiv(x Value, y Value) (Value, bool, error)
- func Index(t *Thread, coll Value, k Value) (Value, error)
- func IntValue(n int64) Value
- func Len(t *Thread, v Value) (Value, error)
- func LightUserDataValue(d LightUserData) Value
- func Mod(x Value, y Value) (Value, bool, error)
- func Mul(x, y Value) (Value, bool)
- func Pow(x, y Value) (Value, bool)
- func RawGet(t *Table, k Value) Value
- func RunChunk1(source []byte, def RuntimeContextDef, stdout io.Writer, opts ...RuntimeOption) (v Value, err error)
- func StringValue(s string) (v Value)
- func Sub(x, y Value) (Value, bool)
- func TableValue(t *Table) Value
- func ThreadValue(t *Thread) Value
- func Unm(x Value) (Value, bool)
- func UnmarshalConst(r io.Reader, budget uint64) (v Value, used uint64, err error)
- func UserDataValue(u *UserData) Value
- func (v Value) AsArray() []Value
- func (v Value) AsBool() bool
- func (v Value) AsCallable() Callable
- func (v Value) AsClosure() *Closure
- func (v Value) AsCode() *Code
- func (v Value) AsCont() Cont
- func (v Value) AsFloat() float64
- func (v Value) AsInt() int64
- func (v Value) AsString() string
- func (v Value) AsTable() *Table
- func (v Value) AsThread() *Thread
- func (v Value) AsUserData() *UserData
- func (v Value) CustomTypeName() string
- func (v Value) Equals(v2 Value) bool
- func (v Value) Hash() uintptr
- func (v Value) Interface() interface{}
- func (v Value) IsNaN() bool
- func (v Value) IsNil() bool
- func (v Value) NumberType() ValueType
- func (v Value) ToString() (string, bool)
- func (v Value) TryBool() (b bool, ok bool)
- func (v Value) TryCallable() (c Callable, ok bool)
- func (v Value) TryClosure() (c *Closure, ok bool)
- func (v Value) TryCode() (c *Code, ok bool)
- func (v Value) TryCont() (c Cont, ok bool)
- func (v Value) TryFloat() (n float64, ok bool)
- func (v Value) TryInt() (n int64, ok bool)
- func (v Value) TryString() (s string, ok bool)
- func (v Value) TryTable() (t *Table, ok bool)
- func (v Value) TryThread() (t *Thread, ok bool)
- func (v Value) TryUserData() (u *UserData, ok bool)
- func (v Value) Type() ValueType
- func (v Value) TypeName() string
- type ValueType
- type Warner
Constants ¶
const ConstTypeMaj = CodeType + 1
ConstTypeMaj Constant types must be less that this.
const (
MetaFieldGcString = "__gc"
)
const QuotasAvailable = true
Variables ¶
var ErrInvalidMarshalPrefix = errors.New("Invalid marshal prefix")
var (
MetaFieldGcValue = StringValue(MetaFieldGcString)
)
var NilValue = Value{}
NilValue is a value holding Nil.
Functions ¶
func BinaryArithmeticError ¶
BinaryArithmeticError returns an error describing the problem with trying to perform x op y.
func Call ¶
Call calls f with arguments args, pushing the results on next. It may use the metamethod '__call' if f is not callable.
func ErrorIsUnexpectedEOF ¶
func HasMarshalPrefix ¶
HasMarshalPrefix returns true if the byte slice passed starts witht the magic prefix for Lua marshalled values.
func IntLen ¶
IntLen returns the length of v as an int64, possibly calling the '__len' metamethod. This is an optimization of Len for an integer output.
func MarshalConst ¶
MarshalConst serializes a const value to the writer w.
func Metacall ¶
Metacall calls the metamethod called method on obj with the given arguments args, pushing the result to the continuation next.
func RawEqual ¶
RawEqual returns two values. The second one is true if raw equality makes sense for x and y. The first one returns whether x and y are raw equal.
func SetIndex ¶
SetIndex sets the item in a collection for the given key, using the '__newindex' metamethod if appropriate. SetIndex always consumes CPU if it doesn't return an error.
func SolemnlyDeclareCompliance ¶
func SolemnlyDeclareCompliance(flags ComplianceFlags, fs ...*GoFunction)
SolemnlyDeclareCompliance is a convenience function that adds the same set of compliance flags to a number of functions. See quotas.md for details about compliance flags.
func ToIntNoString ¶
ToIntNoString returns v as an Int and true if v is actually a valid integer.
func ToNumberValue ¶
func ToNumberValue(v Value) (Value, NumberType)
ToNumberValue returns the Value v as a Float or Int, and if it is a number. If it is not a number, it returns v unchanged and NaN.
func UnaryArithmeticError ¶
UnaryArithmeticError returns an error describing the problem with trying to perform the unary operation op(x).
Types ¶
type Cell ¶
type Cell struct {
// contains filtered or unexported fields
}
Cell is the data structure that represents a reference to a value. Whenever a value is put into a register that contains a cell, it is put in the cell rather than the register itself. It is used in order to implement upvalues in lua. Example:
local x local function f() return x + 1 end x = 3 f()
The variable x is an upvalue in f so when x is set to 3 the upvalue of f must be set to 3. This is achieved by setting the register that contains x to a Cell.
type Closure ¶
Closure is the data structure that represents a Lua function. It is simply a reference to a Code instance and a set of upvalues.
func NewClosure ¶
NewClosure returns a pointer to a new Closure instance for the given code.
func (*Closure) AddUpvalue ¶
AddUpvalue append a new upvalue to the closure.
func (*Closure) Continuation ¶
Continuation implements Callable.Continuation.
func (*Closure) Equals ¶
Equals returns a true if it can assert that c and c1 implement the same function.
func (*Closure) GetUpvalue ¶
GetUpvalue returns the upvalue for c at index n.
func (*Closure) SetUpvalue ¶
SetUpvalue sets the upvalue for c at index n to v.
type Code ¶
type Code struct { UpvalueCount int16 UpNames []string RegCount int16 CellCount int16 // contains filtered or unexported fields }
Code represents the code for a Lua function together with all the constants that this function uses. It can be turned into a closure by adding upvalues.
type ComplianceFlags ¶
type ComplianceFlags uint16
ComplianceFlags represents constraints that the code running must comply with.
const ( // Only execute code checks memory availability before allocating memory ComplyMemSafe ComplianceFlags = 1 << iota // Only execute code that checks cpu availability before executing a // computation. ComplyCpuSafe // Only execute code that complies with IO restrictions (currently only // functions that do no IO comply with this) ComplyIoSafe // Only execute code that is time safe (i.e. it will not block on long // running ops, typically IO) ComplyTimeSafe )
func (ComplianceFlags) AddFlagWithName ¶
func (f ComplianceFlags) AddFlagWithName(name string) (ComplianceFlags, bool)
func (ComplianceFlags) Names ¶
func (f ComplianceFlags) Names() (names []string)
type Cont ¶
type Cont interface { // Push "pushes" a Value to the continuation (arguments before a call, or // before resuming a continuation which has been suspended via "yield"). This is to // pass arguments to the continuation before calling RunInThread. Push(*Runtime, Value) // PushEtc "pushes" varargs to the continutation, this happens e.g. in Lua // code when running "f(...)". PushEtc(*Runtime, []Value) // RunInThread runs the continuation in the given thread, returning either // the next continuation to be run or an error. RunInThread(*Thread) (Cont, error) // Next() returns the continuation that follows after this one (could be // e.g. the caller). Next() Cont // Parent() returns the continuation that initiated this continuation. It // can be the same as Next() but not necessarily. This is useful for giving // meaningful tracebacks, not used by the runtime engine. Parent() Cont // DebugInfo() returns debug info for the continuation. Used for building // error messages and tracebacks. DebugInfo() *DebugInfo }
Cont is an interface for things that can be run in a Thread. Implementations of Cont a typically an invocation of a Lua function or an invocation of a Go function.
type ContextTerminationError ¶
type ContextTerminationError struct {
// contains filtered or unexported fields
}
A ContextTerminationError is an error reserved for when the runtime context should be terminated immediately.
func (ContextTerminationError) Error ¶
func (e ContextTerminationError) Error() string
Error string for a ContextTerminationError
type DebugHookFlags ¶
type DebugHookFlags uint8
DebugHookFlags is the type of representing a set of debug hooks.
const ( HookFlagCall DebugHookFlags // call hook HookFlagReturn // return hook HookFlagLine // line hook HookFlagCount // count hook )
type DebugHooks ¶
type DebugHooks struct { DebugHookFlags DebugHookFlags // hooks enabled HookLineCount int // number of lines for count hook Hook Value // The hook callback }
DebugHooks contains data specifying a debug hooks configuration.
func (*DebugHooks) SetupHooks ¶
func (h *DebugHooks) SetupHooks(newHooks DebugHooks)
SetupHooks configures the debug hooks to use. It does nothing if we are in a hook callback.
type DebugInfo ¶
DebugInfo contains info about a continuation that can be looked at for debugging purposes (and tracebacks).
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is the error type that can be produced by running continuations. Each error has a message and a context, which is a slice of continuations. There is no call stack, but you can imagine you "unwind" the call stack by iterating over this slice.
func (*Error) AddContext ¶
AddContext returns a new error with the lineno / source fields set if not already set.
type GoCont ¶
type GoCont struct { *GoFunction // contains filtered or unexported fields }
GoCont implements Cont for functions written in Go.
func NewGoCont ¶
func NewGoCont(t *Thread, f *GoFunction, next Cont) *GoCont
NewGoCont returns a new pointer to GoCont for the given GoFunction and Cont.
func (*GoCont) BoolArg ¶
BoolArg returns the n-th argument as a string if possible, otherwise a non-nil error. No range check!
func (*GoCont) CallableArg ¶
CallableArg returns the n-th argument as a callable if possible, otherwise a non-nil error. No range check!
func (*GoCont) Check1Arg ¶
Check1Arg returns a non-nil error if the continuation doesn't have at least one arg.
func (*GoCont) CheckNArgs ¶
CheckNArgs returns a non-nil error if the continuation doesn't have at least n args.
func (*GoCont) ClosureArg ¶
ClosureArg returns the n-th argument as a closure if possible, otherwise a non-nil error. No range check!
func (*GoCont) FloatArg ¶
FloatArg returns the n-th argument as a Float if possible, otherwise a non-nil error. No range check!
func (*GoCont) IntArg ¶
IntArg returns the n-th argument as an Int if possible, otherwise a non-nil error. No range check!
func (*GoCont) PushingNext ¶
PushingNext is convenient when implementing go functions. It pushes the given values to c.Next() and returns it.
func (*GoCont) PushingNext1 ¶
PushingNext1 is convenient when implementing go functions. It pushes the given value to c.Next() and returns it.
func (*GoCont) RunInThread ¶
RunInThread implements Cont.RunInThread.
func (*GoCont) StringArg ¶
StringArg returns the n-th argument as a string if possible, otherwise a non-nil error. No range check!
func (*GoCont) TableArg ¶
TableArg returns the n-th argument as a table if possible, otherwise a non-nil error. No range check!
type GoFunction ¶
type GoFunction struct {
// contains filtered or unexported fields
}
A GoFunction is a callable value implemented by a native Go function.
func NewGoFunction ¶
func NewGoFunction(f GoFunctionFunc, name string, nArgs int, hasEtc bool) *GoFunction
NewGoFunction returns a new GoFunction.
func (*GoFunction) Continuation ¶
func (f *GoFunction) Continuation(t *Thread, next Cont) Cont
Continuation implements Callable.Continuation.
func (*GoFunction) SolemnlyDeclareCompliance ¶
func (f *GoFunction) SolemnlyDeclareCompliance(flags ComplianceFlags)
SolemnlyDeclareCompliance adds compliance flags to f. See quotas.md for details about compliance flags.
type LightUserData ¶
type LightUserData struct {
Data interface{}
}
A LightUserData is some Go value of unspecified type wrapped to be used as a lua Value.
type LogWarner ¶
type LogWarner struct {
// contains filtered or unexported fields
}
The default Warner type. It logs messages to a given io.Writer. Note that it is off by default. Issue Warn("@on") to turn it on.
func NewLogWarner ¶
NewLogWarner returns a new LogWarner that will write to dest with the given prefix.
type LuaCont ¶
type LuaCont struct { *Closure // contains filtered or unexported fields }
LuaCont is a Lua continuation, made from a closure, values for registers and some state.
func NewLuaCont ¶
NewLuaCont returns a new LuaCont from a closure and next, a continuation to push results into.
type Metatabler ¶
type Metatabler interface {
Metatable() *Table
}
type NumberType ¶
type NumberType uint16
NumberType represents a type of number
const ( // IsFloat is the type of Floats IsFloat NumberType = 1 << iota // IsInt is the type of Ints IsInt // NaN is the type of values which are not numbers NaN // NaI is a type for values which a not Ints NaI )
func FloatToInt ¶
func FloatToInt(f float64) (int64, NumberType)
FloatToInt turns a float64 into an int64 if possible.
func StringToNumber ¶
func StringToNumber(s string) (n int64, f float64, tp NumberType)
type ResourceReleaser ¶
type ResourceReleaser interface {
ReleaseResources()
}
type Runtime ¶
type Runtime struct { Stdout io.Writer // This is useful for testing / repls // contains filtered or unexported fields }
A Runtime is a Lua runtime. It contains all the global state of the runtime (in particular a reference to the global environment and the main thread).
func New ¶
func New(stdout io.Writer, opts ...RuntimeOption) *Runtime
New returns a new pointer to a Runtime with the given stdout.
func (*Runtime) CheckRequiredFlags ¶
func (m *Runtime) CheckRequiredFlags(flags ComplianceFlags) error
func (*Runtime) CompileAndLoadLuaChunk ¶
func (r *Runtime) CompileAndLoadLuaChunk(name string, source []byte, env Value, scannerOptions ...scanner.Option) (*Closure, error)
CompileAndLoadLuaChunk parses, compiles and loads a Lua chunk from source and returns the closure that runs the chunk in the given global environment.
func (*Runtime) CompileAndLoadLuaChunkOrExp ¶
func (r *Runtime) CompileAndLoadLuaChunkOrExp(name string, source []byte, env Value, scannerOptions ...scanner.Option) (*Closure, error)
CompileAndLoadLuaChunk parses, compiles and loads a Lua chunk from source and returns the closure that runs the chunk in the given global environment.
func (*Runtime) CompileLuaChunk ¶
func (r *Runtime) CompileLuaChunk(name string, source []byte, scannerOptions ...scanner.Option) (*code.Unit, uint64, error)
CompileLuaChunk parses and compiles the source as a Lua Chunk and returns the compile code Unit.
func (*Runtime) CompileLuaChunkOrExp ¶
func (*Runtime) HardLimits ¶
func (m *Runtime) HardLimits() RuntimeResources
func (*Runtime) KillContext ¶
func (m *Runtime) KillContext()
KillContext forcefully terminates the context with the message "force kill".
func (*Runtime) LinearRequire ¶
LinearRequire can be used to actually consume (part of) the resource budget returned by LinearUnused (with the same cpuFactor).
func (*Runtime) LinearUnused ¶
LinearUnused returns an amount of resource combining memory and cpu. It is useful when calling functions whose time complexity is a linear function of the size of their output. As cpu ticks are "smaller" than memory ticks, the cpuFactor arguments allows specifying an increased "weight" for cpu ticks.
func (*Runtime) LoadFromSourceOrCode ¶
func (r *Runtime) LoadFromSourceOrCode(name string, source []byte, mode string, env Value, stripComment bool) (*Closure, error)
LoadFromSourceOrCode loads the given source, compiling it if it is source code or unmarshaling it if it is dumped code. It returns the closure that runs the chunk in the given global environment.
func (*Runtime) LoadLuaUnit ¶
LoadLuaUnit turns a code unit into a closure given an environment env.
func (*Runtime) MainThread ¶
MainThread returns the runtime's main thread.
func (*Runtime) Metatable ¶
Metatable returns the metatalbe of v (looking for '__metatable' in the raw metatable).
func (*Runtime) NewUserDataValue ¶
NewUserDataValue creates a Value containing the user data with the given Go value and metatable. It also registers a GC finalizer if the metadata has a __gc field.
func (*Runtime) Parent ¶
func (m *Runtime) Parent() RuntimeContext
func (*Runtime) ParseLuaChunk ¶
func (r *Runtime) ParseLuaChunk(name string, source []byte, scannerOptions ...scanner.Option) (stat *ast.BlockStat, statSize uint64, err error)
ParseLuaChunk parses a string as a Lua statement and returns the AST.
func (*Runtime) ParseLuaExp ¶
func (r *Runtime) ParseLuaExp(name string, source []byte, scannerOptions ...scanner.Option) (stat *ast.BlockStat, statSize uint64, err error)
ParseLuaExp parses a string as a Lua expression and returns the AST.
func (*Runtime) PopContext ¶
func (m *Runtime) PopContext() RuntimeContext
func (*Runtime) ProcessIoError ¶
ProcessIoError is like PushIoError but its signature makes it convenient to use in a return statement from a GoFunc implementation.
func (*Runtime) Push ¶
Push is a convenience method that pushes a number of values to the continuation c.
func (*Runtime) PushContext ¶
func (m *Runtime) PushContext(ctx RuntimeContextDef)
func (*Runtime) PushIoError ¶
PushIoError is a convenience method that translates ioErr to a value if appropriated and pushes that value to c, else returns an error. It is useful because a number of Go IO errors are considered regular return values by Lua.
func (*Runtime) RawMetatable ¶
RawMetatable returns the raw metatable for a value (that is, not looking at the metatable's '__metatable' key).
func (*Runtime) RefactorCodeConsts ¶
RefactorConsts returns an equivalent *Code this consts "refactored", which means that the consts are slimmed down to only contains the constants required for the function.
func (*Runtime) Registry ¶
Registry returns the Value associated with key in the runtime's registry.
func (*Runtime) ReleaseArrSize ¶
func (*Runtime) ReleaseBytes ¶
func (m *Runtime) ReleaseBytes(n int)
func (*Runtime) ReleaseMem ¶
func (m *Runtime) ReleaseMem(memAmount uint64)
func (*Runtime) ReleaseSize ¶
func (m *Runtime) ReleaseSize(sz uintptr)
func (*Runtime) RequireArrSize ¶
func (*Runtime) RequireBytes ¶
func (*Runtime) RequireCPU ¶
func (m *Runtime) RequireCPU(cpuAmount uint64)
func (*Runtime) RequireMem ¶
func (m *Runtime) RequireMem(memAmount uint64)
func (*Runtime) RequireSize ¶
func (*Runtime) RequiredFlags ¶
func (m *Runtime) RequiredFlags() ComplianceFlags
func (*Runtime) RuntimeContext ¶
func (m *Runtime) RuntimeContext() RuntimeContext
func (*Runtime) SetEnv ¶
SetEnv sets the item in the table t for a string key. Useful when writing libraries
func (*Runtime) SetEnvGoFunc ¶
func (r *Runtime) SetEnvGoFunc(t *Table, name string, f GoFunctionFunc, nArgs int, hasEtc bool) *GoFunction
SetEnvGoFunc sets the item in the table t for a string key to be a GoFunction defined by f. Useful when writing libraries
func (*Runtime) SetRawMetatable ¶
SetRawMetatable sets the metatable for value v to meta.
func (*Runtime) SetRegistry ¶
SetRegistry sets the value associated with the key k to v in the registry.
func (*Runtime) SetStopLevel ¶
func (m *Runtime) SetStopLevel(stopLevel StopLevel)
func (*Runtime) SetStringMeta ¶
SetStringMeta sets the runtime's string metatable (all strings in a runtime have the same metatable).
func (*Runtime) SetTable ¶
Set a value in a table, requiring memory if needed, and always consuming >0 CPU.
func (*Runtime) SetTableCheck ¶
SetTableCheck sets k => v in table T if possible, returning an error if k is nil or NaN.
func (*Runtime) SoftLimits ¶
func (m *Runtime) SoftLimits() RuntimeResources
func (*Runtime) Status ¶
func (m *Runtime) Status() RuntimeContextStatus
func (*Runtime) TerminateContext ¶
func (m *Runtime) TerminateContext(format string, args ...interface{})
TerminateContext forcefully terminates the context with the given message.
func (*Runtime) Traceback ¶
Traceback produces a traceback string of the continuation, requiring memory for the string.
func (*Runtime) UsedResources ¶
func (m *Runtime) UsedResources() RuntimeResources
type RuntimeContext ¶
type RuntimeContext interface { HardLimits() RuntimeResources SoftLimits() RuntimeResources UsedResources() RuntimeResources Status() RuntimeContextStatus Parent() RuntimeContext RequiredFlags() ComplianceFlags SetStopLevel(StopLevel) Due() bool GCPolicy() GCPolicy }
RuntimeContext is an interface implemented by Runtime.RuntimeContext(). It provides a public interface for the runtime context to be used by e.g. libraries (e.g. the runtime package).
func DoInContext ¶
func DoInContext(f func(r *Runtime) error, def RuntimeContextDef, stdout io.Writer, opts ...RuntimeOption) (ctx RuntimeContext, err error)
DoInContext creates a *Runtime r with the constraints from the RuntimeContextDef def, calls f(r) and returns two things: A RuntimeContext instance ctx whose status tells us the outcome (done, killed or error) and in case of error, a non-nil error value.
type RuntimeContextDef ¶
type RuntimeContextDef struct { HardLimits RuntimeResources SoftLimits RuntimeResources RequiredFlags ComplianceFlags MessageHandler Callable GCPolicy }
RuntimeContextDef contains the data necessary to create an new runtime context.
type RuntimeContextStatus ¶
type RuntimeContextStatus uint16
RuntimeContextStatus describes the status of a context
const ( StatusLive RuntimeContextStatus = iota // currently executing StatusDone // finished successfully (no error) StatusError // finished with a Lua error StatusKilled // terminated (either by user or because hard limits were reached) )
func (RuntimeContextStatus) String ¶
func (s RuntimeContextStatus) String() string
type RuntimeOption ¶
type RuntimeOption func(*runtimeOptions)
A RuntimeOption configures the Runtime.
func WithRegPoolSize ¶
func WithRegPoolSize(sz uint) RuntimeOption
WithRegPoolSize set the size of register pool when creating a new Runtime. The default register pool size is 10.
func WithRegSetMaxAge ¶
func WithRegSetMaxAge(age uint) RuntimeOption
WithRegSetMaxAge sets the max age of a register set when creating a new Runtime. The default max age is 10.
func WithRuntimeContext ¶
func WithRuntimeContext(def RuntimeContextDef) RuntimeOption
type RuntimeResources ¶
RuntimeResources describe amount of resources that code can consume. Depending on the context, it could be available resources or consumed resources. For available resources, 0 means unlimited.
func (RuntimeResources) Dominates ¶
func (r RuntimeResources) Dominates(v RuntimeResources) bool
Dominates returns true if the resource count v doesn't reach the resource limit r.
func (RuntimeResources) Merge ¶
func (r RuntimeResources) Merge(r1 RuntimeResources) RuntimeResources
Merge treats the receiver and argument as describing resource limits and returns the resources describing the intersection of those limits.
func (RuntimeResources) Remove ¶
func (r RuntimeResources) Remove(v RuntimeResources) RuntimeResources
Remove lowers the resources accounted for in the receiver by the resources accounted for in the argument.
type SyntaxError ¶
A SyntaxError is a lua syntax error.
func AsSyntaxError ¶
func AsSyntaxError(err error) (snErr *SyntaxError, ok bool)
func NewSyntaxError ¶
func NewSyntaxError(file string, err parsing.Error) *SyntaxError
NewSyntaxError returns a pointer to a SyntaxError for the error err in file.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
Error implements the error interface.
func (*SyntaxError) IsUnexpectedEOF ¶
func (e *SyntaxError) IsUnexpectedEOF() bool
IsUnexpectedEOF returns true if the error signals that EOF was encountered when further tokens were required.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table implements a Lua table.
func (*Table) SetMetatable ¶
SetMetatable sets the table's metatable.
type Termination ¶
type Termination struct {
// contains filtered or unexported fields
}
Termination is a 'dead-end' continuation: it cannot be run.
func NewTermination ¶
func NewTermination(parent Cont, args []Value, etc *[]Value) *Termination
NewTermination returns a new pointer to Termination where the first len(args) values will be pushed into args and the remaining ones will be added to etc if it is non nil, dropped otherwise.
func NewTerminationWith ¶
func NewTerminationWith(parent Cont, nArgs int, hasEtc bool) *Termination
NewTerminationWith creates a new Termination expecting nArgs args and possibly gathering extra args into an etc if hasEtc is true.
func (*Termination) DebugInfo ¶
func (c *Termination) DebugInfo() *DebugInfo
DebugInfo implements Cont.DebugInfo.
func (*Termination) Etc ¶
func (c *Termination) Etc() []Value
Etc returns all the extra args pushed to the termination.
func (*Termination) Get ¶
func (c *Termination) Get(n int) Value
Get returns the n-th arg pushed to the termination.
func (*Termination) Parent ¶
func (c *Termination) Parent() Cont
func (*Termination) Push ¶
func (c *Termination) Push(r *Runtime, v Value)
Push implements Cont.Push. It just accumulates values into a slice.
func (*Termination) PushEtc ¶
func (c *Termination) PushEtc(r *Runtime, etc []Value)
PushEtc implements Cont.PushEtc.
func (*Termination) Reset ¶
func (c *Termination) Reset()
Reset erases all the args pushed to the termination.
func (*Termination) RunInThread ¶
func (c *Termination) RunInThread(t *Thread) (Cont, error)
RunInThread implements Cont.RunInThread. A termination exits immediately so it always returns nil.
type Thread ¶
type Thread struct { *Runtime DebugHooks // contains filtered or unexported fields }
A Thread is a lua thread.
The mutex guarantees that if status == ThreadRunning, then caller is not nil.
func NewThread ¶
NewThread creates a new thread out of a Runtime. Its initial status is suspended. Call Resume to run it.
func (*Thread) CallContext ¶
func (t *Thread) CallContext(def RuntimeContextDef, f func() error) (ctx RuntimeContext, err error)
CallContext pushes a new runtime context on the thread's runtime and attempts to run f() in the thread. If the context runs out of resources while f() is running, all operations should abort and the CallContext should return immediately and not finalizing pending to-be-closed values.
Otherwise (even if f() returns an error), pending to-be-closed values should be finalized.
See quotas.md for details about this API.
func (Thread) CheckRequiredFlags ¶
func (m Thread) CheckRequiredFlags(flags ComplianceFlags) error
func (*Thread) Close ¶
Close a suspended thread. If successful, its status switches to dead. The boolean returned is true if it was possible to close the thread (i.e. it was suspended or already dead). The error is non-nil if there was an error in the cleanup process, or if the thread had already stopped with an error previously.
func (*Thread) CollectGarbage ¶
func (t *Thread) CollectGarbage()
func (*Thread) CurrentCont ¶
CurrentCont returns the continuation currently running (or suspended) in the thread.
func (Thread) HardLimits ¶
func (m Thread) HardLimits() RuntimeResources
func (Thread) KillContext ¶
func (m Thread) KillContext()
KillContext forcefully terminates the context with the message "force kill".
func (Thread) LinearRequire ¶
LinearRequire can be used to actually consume (part of) the resource budget returned by LinearUnused (with the same cpuFactor).
func (Thread) LinearUnused ¶
LinearUnused returns an amount of resource combining memory and cpu. It is useful when calling functions whose time complexity is a linear function of the size of their output. As cpu ticks are "smaller" than memory ticks, the cpuFactor arguments allows specifying an increased "weight" for cpu ticks.
func (Thread) Parent ¶
func (m Thread) Parent() RuntimeContext
func (Thread) PopContext ¶
func (m Thread) PopContext() RuntimeContext
func (Thread) PushContext ¶
func (m Thread) PushContext(ctx RuntimeContextDef)
func (Thread) ReleaseArrSize ¶
func (Thread) ReleaseBytes ¶
func (m Thread) ReleaseBytes(n int)
func (Thread) ReleaseMem ¶
func (m Thread) ReleaseMem(memAmount uint64)
func (Thread) ReleaseSize ¶
func (m Thread) ReleaseSize(sz uintptr)
func (Thread) RequireArrSize ¶
func (Thread) RequireBytes ¶
func (Thread) RequireCPU ¶
func (m Thread) RequireCPU(cpuAmount uint64)
func (Thread) RequireMem ¶
func (m Thread) RequireMem(memAmount uint64)
func (Thread) RequireSize ¶
func (Thread) RequiredFlags ¶
func (m Thread) RequiredFlags() ComplianceFlags
func (*Thread) Resume ¶
Resume execution of a suspended thread. Its status switches to running while its caller's status switches to suspended.
func (*Thread) RunContinuation ¶
RunContinuation runs the continuation c in the thread. It keeps running until the next continuation is nil or an error occurs, in which case it returns the error.
func (Thread) RuntimeContext ¶
func (m Thread) RuntimeContext() RuntimeContext
func (Thread) SetStopLevel ¶
func (m Thread) SetStopLevel(stopLevel StopLevel)
func (Thread) SoftLimits ¶
func (m Thread) SoftLimits() RuntimeResources
func (*Thread) Start ¶
Start starts the thread in a goroutine, giving it the callable c to run. the t.Resume() method needs to be called to provide arguments to the callable.
func (*Thread) Status ¶
func (t *Thread) Status() ThreadStatus
Status returns the status of a thread (suspended, running or dead).
func (Thread) TerminateContext ¶
func (m Thread) TerminateContext(format string, args ...interface{})
TerminateContext forcefully terminates the context with the given message.
func (Thread) UsedResources ¶
func (m Thread) UsedResources() RuntimeResources
type ThreadStatus ¶
type ThreadStatus uint
ThreadStatus is the type of a thread status
const ( ThreadOK ThreadStatus = 0 // Running thread ThreadSuspended ThreadStatus = 1 // Thread has yielded and is waiting to be resumed ThreadDead ThreadStatus = 3 // Thread has finished and cannot be resumed )
Available statuses for threads.
type UserData ¶
type UserData struct {
// contains filtered or unexported fields
}
A UserData is a Go value of any type wrapped to be used as a Lua value. It has a metatable which may allow Lua code to interact with it.
func NewUserData ¶
NewUserData returns a new UserData pointer for the value v, giving it meta as a metatable. This does not register a GC finalizer because access to a runtime is needed for that.
func (*UserData) MarkFlags ¶
HasFinalizer returns true if the user data has finalizing code (either via __gc metamethod or the value needs prefinalization).
func (*UserData) ReleaseResources ¶
func (d *UserData) ReleaseResources()
Prefinalizer runs the value's prefinalize
func (*UserData) SetMetatable ¶
SetMetatable sets d's metatable to m.
type UserDataResourceReleaser ¶
type UserDataResourceReleaser interface {
ReleaseResources(d *UserData)
}
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
A Value is a runtime value.
func Add ¶
Add returns (z, true) where z is the value representing x+y if x and y are numbers, else (NilValue, false).
func ArrayValue ¶
ArrayValue returns a Value holding the given arg.
func AsValue ¶
func AsValue(i interface{}) Value
AsValue returns a Value for the passed interface. Use carefully, as it may trigger allocations (e.g. AsValue(1) will allocate as the interface holding 1 will put 1 on the heap).
func Call1 ¶
Call1 is a convenience method that calls f with arguments args and returns exactly one value.
func Div ¶
Div returns (z, true) where z is the (float) value representing x/y if x and y are numbers, else (NilValue, false).
func ErrorValue ¶
ErrorValue extracts a Value from err. If err is an *Error then it returns its Value(), otherwise it builds a Value from the error string.
func FloatValue ¶
FloatValue returns a Value holding the given arg.
func FunctionValue ¶
FunctionValue returns a Value holding the given arg.
func Idiv ¶
Div returns (z, true, nil) where z is the (integer) value representing x//y if x and y are numbers and y != 0, if y == 0 it returns (NilValue, true, div_by_zero_error), else (NilValue, false, nil) if x or y is not a number.
func Index ¶
Index returns the item in a collection for the given key k, using the '__index' metamethod if appropriate. Index always consumes CPU.
func LightUserDataValue ¶
func LightUserDataValue(d LightUserData) Value
LightUserDataValue returns a Value holding the given arg.
func Mod ¶
Mod returns (z, true, nil) where z is the (integer or float) value representing x%y if x and y are numbers and y != 0, if y == 0 it returns (NilValue, true, mod_by_zero_error), else (NilValue, false, nil) if x or y is not a number.
func Mul ¶
Mul returns (z, true) where z is the value representing x*y if x and y are numbers, else (NilValue, false).
func Pow ¶
Pow returns (z, true) where z is the (float) value representing x^y if x and y are numbers, else (NilValue, false).
func RawGet ¶
RawGet returns the item in a table for the given key, or nil if t is nil. It doesn't check the metatable of t.
func RunChunk1 ¶
func RunChunk1(source []byte, def RuntimeContextDef, stdout io.Writer, opts ...RuntimeOption) (v Value, err error)
RunChunk1 runs source code in a runtime constrained by def. It returns the value returned by the chunk and possibly an error if execution failed (including when the runtime was killed).
func StringValue ¶
StringValue returns a Value holding the given arg.
func Sub ¶
Sub returns (z, true) where z is the value representing x-y if x and y are numbers, else (NilValue, false).
func ThreadValue ¶
ThreadValue returns a Value holding the given arg.
func Unm ¶
Unm returns (z, true) where z is the value representing -x if x is a number, else (NilValue, false).
func UnmarshalConst ¶
UnmarshalConst reads from r to deserialize a const value.
func UserDataValue ¶
UserDataValue returns a Value holding the given arg.
func (Value) AsCallable ¶
AsCallable returns v as a Callable if possible (or panics)). It is an optimisation as type assertion in Go seems to have a significant cost.
func (Value) AsCont ¶
AsCont returns v as a Cont, by looking at the concrete type (or panics). It is an optimisation as type assertion in Go seems to have a significant cost.
func (Value) AsUserData ¶
AsUserData returns v as a *UserData (or panics).
func (Value) CustomTypeName ¶
CustomTypeName is like TypeName but can be changed if the metatable has a __name field.
func (Value) Equals ¶
Equals returns true if v is equal to v2. Provided that v and v2 have been built with the official constructor functions, it is equivalent to but slightly faster than '=='.
func (Value) Interface ¶
func (v Value) Interface() interface{}
Interface turns the Value into an interface. As AsValue, this can trigger allocations so use with caution.
func (Value) IsNaN ¶
IsNaN returns true if v is a FloatValue which has a NaN value. It is trying to do this as efficiently as possible.
func (Value) NumberType ¶
NumberType return the ValueType of v if it is a number, otherwise UnknownType.
func (Value) ToString ¶
ToString returns a simple string representation of a Value. The boolean returned specifies whether this is a good string value or not ("good" should be defined).
func (Value) TryCallable ¶
TryCallable converts v to type Callable if possible by looking at the possible concrete types (ok is false otherwise). It is an optimisation as type assertion in Go seems to have a significant cost.
func (Value) TryClosure ¶
TryClosure converts v to type *Closure if possible (ok is false otherwise).
func (Value) TryCont ¶
TryCont returns v as a Cont, by looking at the concrete type (ok is false if it doesn't implement the Cont interface). It is an optimisation as type assertion in Go seems to have a significant cost.
func (Value) TryUserData ¶
TryUserData converts v to type *UserData if possible (ok is false otherwise).
type Warner ¶
type Warner interface {
Warn(msgs ...string)
}
Warner is the interface for the Lua warning system. The Warn function emits warning, when called with one argument, if the argument starts with '@' then the message is a control message. These messages are not emitted but control the behaviour of the Warner instance.
Source Files ¶
- arith.go
- bitwise.go
- callable.go
- cell.go
- closure.go
- comp.go
- cont.go
- debug.go
- debughooks.go
- error.go
- gocont.go
- gocontpool.go
- gofunction.go
- hash.go
- hashtable.go
- lib.go
- loadunit.go
- luacont.go
- luacontpool.go
- marshal.go
- metatables.go
- numconv.go
- regpool.go
- runtime.go
- runtimecontext.go
- runtimecontextmanager.go
- syntaxerror.go
- table.go
- termination.go
- thread.go
- userdata.go
- value.go
- valuetype.go
- warn.go
- wrappers.go