Documentation ¶
Overview ¶
func (x *Table) Next(key Value) (Value, Value) {} func (x *Table) Length() int {} func (x *Table) Append(value Value) {} func (x *Table) Insert(index int, value Value) {} func (x *Table) Remove(index int) (value Value) {} func (x *Table) RawGet(key Value) (value Value) {} func (x *Table) RawGetInt(key int) (value Value) {} func (x *Table) RawGetKey(key Value) (value Value) {} func (x *Table) RawGetStr(key string) (value Value) {} func (x *Table) RawSet(key, value Value) {} func (x *Table) RawSetKey(key, value Value) {} func (x *Table) RawSetInt(key int, value Value) {} func (x *Table) RawSetStr(key string, value Value) {}
Index ¶
- Constants
- Variables
- func DBG(fr *Frame, halt bool)
- func IsFloat(value Value) bool
- func IsInt(value Value) bool
- func IsNone(value Value) bool
- func IsNumber(value Value) bool
- func Truth(value Value) bool
- func UpValueIndex(index int) int
- type Bool
- type CallInfo
- type Callable
- type Closure
- type Debug
- func (debug *Debug) CurrentLine() int
- func (debug *Debug) IsTailCall() bool
- func (debug *Debug) IsVararg() bool
- func (debug *Debug) LastLineDefined() int
- func (debug *Debug) LineDefined() int
- func (debug *Debug) Name() string
- func (debug *Debug) NameWhat() string
- func (debug *Debug) NumParams() int
- func (debug *Debug) NumUps() int
- func (debug *Debug) ShortSrc() string
- func (debug *Debug) Source() string
- func (debug *Debug) What() string
- type Float
- type Frame
- type Func
- type HasAdd
- type HasAnd
- type HasConcat
- type HasDiv
- type HasEquals
- type HasIndex
- type HasLength
- type HasLessEqual
- type HasLessThan
- type HasMinus
- type HasMod
- type HasMul
- type HasNewIndex
- type HasNot
- type HasOr
- type HasPow
- type HasShl
- type HasShr
- type HasSub
- type HasXor
- type HookEvent
- type Int
- type Mode
- type Nil
- type Number
- type Object
- type Op
- type Option
- type State
- func (state *State) AbsIndex(index int) int
- func (state *State) ArgCheck(cond bool, arg int, msg string)
- func (state *State) ArgError(arg int, msg string) int
- func (state *State) Arith(op Op)
- func (state *State) AtPanic(panicFn Func) Func
- func (state *State) Call(args, rets int)
- func (state *State) CallMeta(index int, event string) bool
- func (state *State) CheckAny(index int) Value
- func (state *State) CheckInt(index int) int64
- func (state *State) CheckNumber(index int) float64
- func (state *State) CheckStack(needed int) bool
- func (state *State) CheckString(index int) string
- func (state *State) CheckType(index int, typ Type)
- func (state *State) CheckUserData(index int, metaType string) (data interface{})
- func (state *State) Close()
- func (state *State) Compare(op Op, i1, i2 int) bool
- func (state *State) Concat(n int)
- func (state *State) Debug(halt bool)
- func (state *State) Dump(strip bool) []byte
- func (state *State) DumpStack(w io.Writer)
- func (state *State) Error() int
- func (state *State) Errorf(format string, args ...interface{}) int
- func (state *State) ExecChunk(filename string, source interface{}, mode Mode) error
- func (state *State) ExecFile(file string) error
- func (state *State) ExecFrom(r io.Reader) error
- func (state *State) ExecText(text string) error
- func (state *State) FileResult(err error, filename string) int
- func (state *State) GetField(index int, field string) Type
- func (state *State) GetGlobal(name string) Type
- func (state *State) GetIndex(index int, entry int64) Type
- func (state *State) GetInfo(debug *Debug, options string) error
- func (state *State) GetMetaField(index int, event string) Type
- func (state *State) GetMetaTable(name string) Type
- func (state *State) GetMetaTableAt(index int) bool
- func (state *State) GetStack(debug *Debug, depth int) error
- func (state *State) GetSubTable(index int, field string) bool
- func (state *State) GetTable(index int) Type
- func (state *State) GetUpValue(function, index int) (name string)
- func (state *State) Insert(index int)
- func (state *State) IsBool(index int) bool
- func (state *State) IsFloat(index int) bool
- func (state *State) IsFunc(index int) bool
- func (state *State) IsGoFunc(index int) bool
- func (state *State) IsInt(index int) bool
- func (state *State) IsNil(index int) bool
- func (state *State) IsNone(index int) bool
- func (state *State) IsNoneOrNil(index int) bool
- func (state *State) IsNumber(index int) bool
- func (state *State) IsString(index int) bool
- func (state *State) IsThread(index int) bool
- func (state *State) Length(index int) int
- func (state *State) LoadChunk(filename string, source interface{}, mode Mode) error
- func (state *State) LoadFile(file string) error
- func (state *State) LoadFrom(r io.Reader) error
- func (state *State) LoadText(text string) error
- func (state *State) Log(args ...interface{})
- func (state *State) Logf(format string, args ...interface{})
- func (state *State) Main(args ...string) error
- func (state *State) NewMetaTable(name string) bool
- func (state *State) NewTable()
- func (state *State) NewTableSize(narr, nrec int)
- func (state *State) Next(index int) (more bool)
- func (state *State) OptInt(index int, optInt int64) int64
- func (state *State) OptNumber(index int, optNum float64) float64
- func (state *State) OptString(index int, optStr string) string
- func (state *State) PCall(args, rets, msgh int) (err error)
- func (state *State) Pop() Value
- func (state *State) PopN(n int) []Value
- func (state *State) Preload(module string, loader Func)
- func (state *State) Push(any interface{}) int
- func (state *State) PushClosure(fn Func, nups uint8)
- func (state *State) PushGlobals()
- func (state *State) PushIndex(index int)
- func (state *State) RawEqual(i1, i2 int) bool
- func (state *State) RawGet(index int) Type
- func (state *State) RawGetIndex(index, entry int) Type
- func (state *State) RawGetPtr(index int, udata *Object) Type
- func (state *State) RawLen(index int) int
- func (state *State) RawSet(index int)
- func (state *State) RawSetIndex(index, entry int)
- func (state *State) RawSetPtr(index int, udata *Object)
- func (state *State) Register(name string, fn Func)
- func (state *State) Remove(index int)
- func (state *State) Replace(index int)
- func (state *State) Require(module string, loader Func, global bool)
- func (state *State) Rotate(index, n int)
- func (state *State) SetField(index int, field string)
- func (state *State) SetFuncs(funcs map[string]Func, nups uint8)
- func (state *State) SetGlobal(name string)
- func (state *State) SetIndex(index int, entry int64)
- func (state *State) SetMetaTable(name string)
- func (state *State) SetMetaTableAt(index int)
- func (state *State) SetTable(index int)
- func (state *State) SetTop(top int)
- func (state *State) SetUpValue(fnIndex, upIndex int) (name string)
- func (state *State) Status() ThreadStatus
- func (ls *State) String() string
- func (state *State) TestUserData(index int, metaType string) (data interface{})
- func (state *State) ToBool(index int) bool
- func (state *State) ToClosure(index int) *Closure
- func (state *State) ToFunc(index int) Func
- func (state *State) ToInt(index int) int64
- func (state *State) ToNumber(index int) float64
- func (state *State) ToString(index int) string
- func (state *State) ToStringMeta(index int) string
- func (state *State) ToTable(index int) Table
- func (state *State) ToThread(index int) *State
- func (state *State) ToUserData(index int) *Object
- func (state *State) Top() int
- func (state *State) TryFloat(index int) (float64, bool)
- func (state *State) TryInt(index int) (int64, bool)
- func (state *State) TryNumber(index int) (Number, bool)
- func (state *State) TryString(index int) (string, bool)
- func (state *State) TypeAt(index int) Type
- func (state *State) UpValueID(function, index int) interface{}
- func (state *State) UpValueJoin(func1, n1, func2, n2 int)
- func (state *State) Version() *float64
- func (state *State) Where(level int)
- func (state *State) XMove(dst *State, n int)
- type String
- type Table
- type ThreadStatus
- type Type
- type Value
Constants ¶
const ( // DefaultLuaLibsPrefix is the prefix for the directory containing lua shared libraries. DefaultLuaHomePrefix = DefaultLuaRootPrefix + "share/lua/5.3/" // DefaultLuaLibsPrefix is the prefix for the directory containing lua library modules. DefaultLuaLibsPrefix = DefaultLuaRootPrefix + "lib/lua/5.3/" // DefaultLuaRootPrefix is the prefix for the default lua root directory. DefaultLuaRootPrefix = "/usr/local/" )
const ( // Name of the environment variable that Lua checks to set // package.gopath. This takes precedence over LUA_GOPATH. EnvVarLuaGoPath53 = "$LUA_GOPATH_5_3" // Name of the environment variable that Lua checks to set // package.gopath. EnvVarLuaGoPath = "$LUA_GOPATH" // Name of the environment variable that Lua checks to set // package.path. This takes precedence over LUA_PATH. EnvVarLuaPath53 = "$LUA_PATH_5_3" // Name of the environment variable that Lua checks to set // package.path. EnvVarLuaPath = "$LUA_PATH" // Versioned equivalent to LUA_INIT. EnvVarLuaInit53 = "$LUA_INIT_5_3" // When called without option -E, the interpreter checks for // an environment variable LUA_INIT_5_3 (or LUA_INIT if the // versioned name is not defined) before running any argument. // If the variable content has the format @filename, then lua // executes the file. Otherwise, lua executes the string itself. EnvVarLuaInit = "$LUA_INIT" // Name of the environment variable that Lua checks to set // the Lua root dir. EnvVarLuaRoot = "$LUA_ROOT" )
const ( // The default value used to initialize LuaPath if not provided and // the environment variables LUA_PATH_5_3 and LUA_PATH are unset. DefaultLuaPath = DefaultLuaHomePrefix + "?.lua;" + DefaultLuaHomePrefix + "?/init.lua;" + DefaultLuaLibsPrefix + "?.lua;" + DefaultLuaLibsPrefix + "?/init.lua;./?.lua;./?/init.lua" // The default value used to initialize LuaGoPath if not provided and // the environment variables LUA_GOPATH_5_3 and LUA_GOPATH are unset. DefaultLuaGoPath = DefaultLuaLibsPrefix + "?.so;" + DefaultLuaLibsPrefix + "loadall.so;./?.so" )
const ( // The Lua version to which this implementation conforms Version = "Lua 5.3" // Option for multiple returns in 'lua_pcall' and 'lua_call' MultRets = -1 )
const ( // RegistryIndex is the pseudo-index for the registry table. RegistryIndex = -DefaultStackMax - 1000 // MainThreadIndex is the registry index for the main thread of the main state. MainThreadIndex = 1 // GlobalsIndex is the registry index for the global environment. GlobalsIndex = 2 // Key, in the registry, for table of loaded modules. LoadedKey = "_LOADED" // Key, in the registry, for table or preloaded loaders. PreloadKey = "_PRELOAD" )
const ( // Maximum valid index and maximum size of stack. DefaultStackMax = 1000000 // Minimum Lua stack available to a function. DefaultStackMin = 20 // Size allocated for new stacks. InitialStackNew = 2 * DefaultStackMin // Initial space allocate for UpValues. InitialFreeMax = 5 // Extra stack space to handle metamethod calls and some other extras. ExtraStack = 5 // Maximum number of upvalues in a closure (both lua and go). // Value must fit in a VM register. MaxUpValues = 255 // Limit for table tag-method chains (to avoid loops). MaxMetaChain = 2000 // Maximum depth for nested Go calls and syntactical nested non-terminals // in a program. // // Value must be < 255. MaxCalls = 255 // Number of list items to accumulate before a SETLIST instruction. FieldsPerFlush = 50 )
const ( True = Bool(true) False = Bool(false) )
const HookKey = 0
The hook table at registry[HookKey] maps threads to their current hook function.
const None = Nil(0)
Variables ¶
var ( // Config is a string describing some compile-time configurations for packages. // This string consists of a sequence of lines: // // The first line is the directory separator string. Default is '\' for Windows // and '/' for all other systems. // // The second line is the character that separates templates in a path. Default // is ';'. // // The third line is the string that marks the substitution points in a template. // Default is '?'. // // The fourth line is a string that, in a path in Windows, is replaced by the // executable's directory. Default is '!'. // // The fifth line is a mark to ignore all text after it when building the luaopen_ // function name. Default is '-'. Config = "/\n;\n?\n!\n-" // Root is the path to the Lua root directory. // // On init, Root is set to the value of the environment variable LUA_ROOT; // otherwise Root is set to DefaultLuaRootPrefix. EnvRoot = expand(EnvVarLuaRoot, DefaultLuaRootPrefix) // Home is the path to the directory Lua used by require to search for lua loaders. // // At start-up, Lua initializes this variable using the value of the environment variable // LUA_PATH_5_3 or LUA_PATH. Any ";;" in the environment variables value is replaced by // the default path. // // On init, Home is set to the value of the environment variable LUA_PATH; // otherwise Home is set to DefaultLuaPath. EnvHome = expand(EnvVarLuaGoPath, DefaultLuaGoPath) // Path is the path to the directory used by Lua require to search for a go loader. // // Lua initializes the LuaGoPath (package.gopath) in the same way it initializes // LuaPath (package.path), using the environment variable LUA_GOPATH_5_3 or LUA_GOPATH. // // On init, Path is set to the value of the environment variable LUA_GOPATH; // otherwise Path is set to DefaultLuaGoPath. EnvPath = expand(EnvVarLuaPath, DefaultLuaPath) // EnvInit is the path to file or string used to initialize Lua. // // export LUA_INIT=@/path/to/file/init.lua EnvInit = expand(EnvVarLuaInit, "") )
Functions ¶
func UpValueIndex ¶
When a function is created, it is possible to associate some values with it, thus creating a closure (see PushClosure); these values are called upvalues and are accessible to the function whenever it is called.
Whenever a function is called, its upvalues are located at specific pseudo-indices. These pseudo-indices are produced by the macro UpValueIndex.
The first upvalue associated with a function is at index UpValueIndex(1), and so on. Any access to UpValueIndex(n), where n is greater than the number of upvalues of the current function (but not greater than 256, which is one plus the maximum number of upvalues in a closure), produces an acceptable but invalid index.
Types ¶
type Callable ¶
__call: The call operation func(args). This event happens when Lua tries to call a non-function value (that is, func is not a function). The metamethod is looked up in func. If present, the metamethod is called with func as its first argument, followed by the arguments of the original call (args). All results of the call are the result of the operation.
This is the only metamethod that allows multiple results.
type Closure ¶
type Closure struct {
// contains filtered or unexported fields
}
closure represents a lua or go function closure.
type Debug ¶
type Debug struct {
// contains filtered or unexported fields
}
debug is a structure used to carry different pieces of information about a function or an activation record. state.GetStack fills only the private fields of this struct, for later use. To fill the other fields, use state.GetInfo.
See https://www.lua.org/manual/5.3/manual.html#lua_Debug
func (*Debug) CurrentLine ¶
func (*Debug) IsTailCall ¶
func (*Debug) LastLineDefined ¶
func (*Debug) LineDefined ¶
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame is the context to execute a function closure.
type HasAdd ¶
__add: the addition (+) operation. If any operand for an addition is not a number (nor a string coercible to a number), Lua will try to call a metamethod. First, Lua will check the first operand (even if it is valid). If that operand does not define a metamethod for __add, then Lua will check the second operand. If Lua can find a metamethod, it calls the metamethod with the two operands as arguments, and the result of the call (adjusted to one value) is the result of the operation.
Otherwise, it raises an error.
type HasAnd ¶
__band: the bitwise AND (&) operation. Behavior similar to the addition operation, except that Lua will try a metamethod if any operand is neither an integer nor a value coercible to an integer (see §3.4.3).
type HasConcat ¶
__concat: the concatenation (..) operation. Behavior similar to the addition operation, except that Lua will try a metamethod if any operand is neither a string nor a number which is always coercible to a string.
type HasEquals ¶
__eq: the equal (==) operation. Behavior similar to the addition operation, except that Lua will try a metamethod only when the values being compared are either both tables or both full userdata and they are not primitively equal. The result of the call is always converted to a boolean.
type HasIndex ¶
__index: The indexing access operation table[key]. This event happens when table is not a table or when key is not present in table. The metamethod is looked up in table. Despite the name, the metamethod for this event can be either a function or a table. If it is a function, it is called with table and key as arguments, and the result of the call (adjusted to one value) is the result of the operation. If it is a table, the final result is the result of indexing this table with key. (This indexing is regular, not raw, and therefore can trigger another metamethod.)
type HasLength ¶
__len: the length (#) operation. If the object is not a string, Lua will try its metamethod. If there is a metamethod, Lua calls it with the object as argument, and the result of the call (always adjusted to one value) is the result of the operation. If there is no metamethod but the object is a table, then Lua uses the table length operation (see §3.4.7).
Otherwise, Lua raises an error.
type HasLessEqual ¶
__le: the less equal (<=) operation. Unlike other operations, the less-equal operation can use two different events.
First, Lua looks for the __le metamethod in both operands, like in the less than operation. If it cannot find such a metamethod, then it will try the __lt metamethod, assuming that a <= b is equivalent to not (b < a). As with the other comparison operators, the result is always a boolean.
This use of the __lt event can be removed in future versions; it is also slower than a real __le metamethod.
type HasLessThan ¶
__lt: the less than (<) operation. Behavior similar to the addition operation, except that Lua will try a metamethod only when the values being compared are neither both numbers nor both strings.
The result of the call is always converted to a boolean.
type HasMinus ¶
__unm: the negation (unary -) operation. Behavior similar to the addition operation.
type HasNewIndex ¶
__newindex: The indexing assignment table[key] = value. Like the index event, this event happens when table is not a table or when key is not present in table. The metamethod is looked up in table. Like with indexing, the metamethod for this event can be either a function or a table.
If it is a function, it is called with table, key, and value as arguments. If it is a table, Lua does an indexing assignment to this table with the same key and value. (This assignment is regular, not raw, and therefore can trigger another metamethod.)
Whenever there is a __newindex metamethod, Lua does not perform the primitive assignment. If necessary, the metamethod itself can call rawset to do the assignment.
type HasNot ¶
__bnot: the bitwise NOT (unary ~) operation. Behavior similar to the bitwise AND operation.
type HasShl ¶
__shl: the bitwise left shift (<<) operation. Behavior similar to the bitwise AND operation.
type HasShr ¶
__shr: the bitwise right shift (>>) operation. Behavior similar to the bitwise AND operation.
type HasXor ¶
__bxor: the bitwise exclusive OR (binary ~) operation. Behavior similar to the bitwise AND operation.
type Mode ¶
type Mode uint
Mode is a set of flags (or 0). They control where Lua chunk loading is limited to binary chunks, text chunks, or both (default).
type Op ¶
type Op int
Op represents a Lua arithmetic, bitwise, or relational operator.
const ( // Arithmetic Operators OpAdd Op = 1 + iota // '+' OpSub // '-' OpMul // '*' OpMod // '%' OpPow // '^' OpDiv // '/' OpQuo // '//' OpMinus // '-' (unary) // Bitwise Operators OpOr // '|' OpAnd // '&' OpXor // '~' OpRsh // '>>' OpLsh // '<<' OpNot // '~' (unary) // Relational Operators OpLt // '<' OpLe // '<=' OpEq // '==' OpGt // '>' OpGe // '>=' OpNe // '~=' // Miscellaneous Operators OpConcat // '..' OpLength // '#' )
type Option ¶
type Option func(*config)
Option is an optional configuration for a Lua state.
func WithChecks ¶
WithChecks returns an Option that instruction a Lua state to perform API checks.
func WithVerbose ¶
WithVerbose returns an Option that toggles verbose logging.
type State ¶
type State struct {
// contains filtered or unexported fields
}
'per thread' state.
func (*State) AbsIndex ¶
AbsIndex converts the acceptable index idx into an equivalent absolute index; that is, one that does not depend on the stack top).
func (*State) ArgCheck ¶
ArgCheck checks whether cond is true. If it is not, raises an error with a standard message (see ArgError).
See https://www.lua.org/manual/5.3/manual.html#luaL_argcheck
func (*State) ArgError ¶
ArgError raises an error reporting a problem with argument arg of the Go function that called it, using a standard message that includes msg as a comment: ```bad argument #arg to 'funcname' (msg)```.
This function never returns.
See https://www.lua.org/manual/5.3/manual.html#luaL_argerror
func (*State) Arith ¶
Performs an arithmetic or bitwise operation over the two values (or one, in the case of negations) at the top of the stack, with the value at the top being the second operand, pops these values, and pushes the result of the operation. The function follows the semantics of the corresponding Lua operator (that is, it may call metamethods).
The value of op must be one of the following constants:
- LUA_OPADD: performs addition (+)
- LUA_OPSUB: performs subtraction (-)
- LUA_OPMUL: performs multiplication (*)
- LUA_OPDIV: performs float division (/)
- LUA_OPIDIV: performs floor division (//)
- LUA_OPMOD: performs modulo (%)
- LUA_OPPOW: performs exponentiation (^)
- LUA_OPUNM: performs mathematical negation (unary -)
- LUA_OPBNOT: performs bitwise NOT (~)
- LUA_OPBAND: performs bitwise AND (&)
- LUA_OPBOR: performs bitwise OR (|)
- LUA_OPBXOR: performs bitwise exclusive OR (~)
- LUA_OPSHL: performs left shift (<<)
- LUA_OPSHR: performs right shift (>>)
func (*State) Call ¶
Call calls a function.
To call a function you must use the following protocol: first, the function to be called is pushed onto the stack; then, the arguments to the function are pushed in direct order; that is, the first argument is pushed first. Finally you call lua_call; nargs is the number of arguments that you pushed onto the stack. All arguments and the function value are popped from the stack when the function is called. The function results are pushed onto the stack when the function returns. The number of results is adjusted to nresults, unless nresults is LUA_MULTRET. In this case, all results from the function are pushed; Lua takes care that the returned values fit into the stack space, but it does not ensure any extra space in the stack. The function results are pushed onto the stack in direct order (the first result is pushed first), so that after the call the last result is on the top of the stack.
Note that the code above is balanced: at its end, the stack is back to its original configuration. This is considered good programming practice.
func (*State) CallMeta ¶
CallMeta calls a metamethod.
If the object at index obj has a metatable and this metatable has a field event, this function calls this field passing the object as its only argument. In this case this function returns true and pushes onto the stack the value returned by the call. If there is no metatable or no metamethod, this function returns false (without pushing any value on the stack).
See https://www.lua.org/manual/5.3/manual.html#luaL_callmeta
func (*State) CheckAny ¶
CheckAny checks whether the function has an argument of any type (including nil) at position index.
See https://www.lua.org/manual/5.3/manual.html#luaL_checkany
func (*State) CheckInt ¶
CheckInt checks whether the function argument at index is an integer (or can be converted to an integer) and returns the value as an integer.
See https://www.lua.org/manual/5.3/manual.html#luaL_checkinteger
func (*State) CheckNumber ¶
CheckNumber checks whether the function argument arg is a number and returns this number.
See http://www.lua.org/manual/5.3/manual.html#luaL_checknumber
func (*State) CheckStack ¶
CheckStack ensures that the stack has space for at least n extra slots (that is, that you can safely push up to n values into it). It returns false if it cannot fulfill the request, either because it would cause the stack to be larger than a fixed maximum size (typically at least several thousand elements) or because it cannot allocate memory for the extra space.
This function never shrinks the stack; if the stack already has space for the extra slots, it is left unchanged.
func (*State) CheckString ¶
CheckString checks whether the function argument at index is a string and returns this string. This function uses ToString to get its result, so all conversions and caveats of that function apply here.
See https://www.lua.org/manual/5.3/manual.html#luaL_checkstring
func (*State) CheckType ¶
CheckType checks whether the function argument at index has type typ.
See https://www.lua.org/manual/5.3/manual.html#luaL_checktype
func (*State) CheckUserData ¶
CheckUserData checks whether the function argument arg is a userdata of the type metaType (see NewMetaTable) and returns the userdata address (see ToUserData).
See https://www.lua.org/manual/5.3/manual.html#luaL_checkudata
func (*State) Close ¶
func (state *State) Close()
Destroys all objects in the given Lua state (calling the corresponding garbage-collection metamethods, if any) and frees all dynamic memory used by this state. In several platforms, you may not need to call this function, because all resources are naturally released when the host program ends. On the other hand, long-running programs that create multiple states, such as daemons or web servers, will probably need to close states as soon as they are not needed.
func (*State) Compare ¶
Compares two Lua values. Returns 1 if the value at index index1 satisfies op when compared with the value at index index2, following the semantics of the corresponding Lua operator (that is, it may call metamethods).
Otherwise returns false. Also returns false if any of the indices are invalid.
The value of op must be one of the following constants:
- LUA_OPEQ: compares for equality (==)
- LUA_OPLT: compares for less than (<)
- LUA_OPLE: compares for less or equal (<=)
func (*State) Concat ¶
Concatenates the n values at the top of the stack, pops them, and leaves the result at the top. If n is 1, the result is the single value on the stack (that is, the function does nothing); if n is 0, the result is the empty string. Concatenation is performed following the usual semantics of Lua (see https://www.lua.org/manual/5.3/manual.html#3.4.6).
func (*State) Dump ¶
Dump dumps a function as a binary chunk. Receives a Lua function on top of the stack and produces a binary chunk that, if loaded again, results in a function equivalent to the one dumped.
If strip is true, the binary representation may not include all debug information about the function, to save space.
func (*State) Error ¶
Generates a Lua error, using the value at the top of the stack as the error object.
This function does a long jump, and therefore never returns (see luaL_error).
func (*State) Errorf ¶
Errorf raises an error.
The error message format is given by fmt plus any extra arguments, following the same rules of lua_pushfstring. It also adds at the beginning of the message the file name and the line number where the error occurred, if this information is available.
This function never returns, but it is an idiom to use it in Go functions as return state.Errorf(fmt, args).
func (*State) ExecChunk ¶
Exec loads and runs a Lua chunk returning the result (if any) or an error (if any).
The Lua chunk may be provided via the filename of the source file, or via the source parameter.
If source != nil, Do loads the source from source and the filename is only used recording position information.
func (*State) ExecText ¶
ExecText uses Exec to load and execute the given string.
See https://www.lua.org/manual/5.3/manual.html#luaL_dostring
func (*State) FileResult ¶
FileResult procudes the return values for file-related function in the standard library (io.open, os.rename, file:seek, etc.).
See https://www.lua.org/manual/5.3/manual.html#luaL_fileresult
func (*State) GetField ¶
Pushes onto the stack the value t[k], where t is the value at the given index.
As in Lua, this function may trigger a metamethod for the "index" event (see §2.4).
Returns the type of the pushed value.
func (*State) GetGlobal ¶
Pushes onto the stack the value of the global name.
Returns the type of that value.
func (*State) GetIndex ¶
Pushes onto the stack the value t[i], where t is the value at the given index.
As in Lua, this function may trigger a metamethod for the "index" event (see §2.4).
Returns the type of the pushed value.
func (*State) GetInfo ¶
DebugInfo returns debug information about a specific function or function invocation.
To get information about a function invocation, the parameter ar must be a valid activation record that was filled by a previous call to lua_getstack or given as argument to a hook (see Hook).
To get information about a function, you push it onto the stack and start the what string with the character '>'. (In that case, lua_getinfo pops the function from the top of the stack.) For instance, to know in which line a function f was defined, you can write the following code:
lua_Debug ar; lua_getglobal(L, "f"); /* get global 'f' */ lua_getinfo(L, ">S", &ar); printf("%d\n", ar.linedefined);
Each character in the string what selects some fields of the structure ar to be filled or a value to be pushed on the stack:
'n': fills in the field name and namewhat; 'S': fills in the fields source, short_src, linedefined, lastlinedefined, and what; 'l': fills in the field currentline; 't': fills in the field istailcall; 'u': fills in the fields nups, nparams, and isvararg; 'f': pushes onto the stack the function that is running at the given level; 'L': pushes onto the stack a table whose indices are the numbers of the lines that are valid on the function. (A valid line is a line with some associated code, that is, a line where you can put a break point. Non-valid lines include empty lines and comments.)
If this option is given together with option 'f', its table is pushed after the function.
This function returns 0 on error (for instance, an invalid option in what).
func (*State) GetMetaField ¶
GetMetaField pushes onto the stack the field event from the metatable of the object at index and returns the type of the pushed value. If the object does not have a metatable, or if the metatable does not have this field, pushes nothing and returns NilType.
See https://www.lua.org/manual/5.3/manual.html#luaL_getmetafield
func (*State) GetMetaTable ¶
GetMetaTable pushes onto the stack the metatable associated with name in the registry (see luaL_newtable) (nil if there is no metatable associated with that name). Returns the type of the pushed value.
See https://www.lua.org/manual/5.3/manual.html#luaL_getmetatable
func (*State) GetMetaTableAt ¶
If the value at the given index has a metatable, the function pushes that metatable onto the stack and returns 1. Otherwise, the function returns 0 and pushes nothing on the stack.
See https://www.lua.org/manual/5.3/manual.html#lua_getmetatable
func (*State) GetStack ¶
GetStack returns debug information about the interpreter runtime stack.
This function fills parts of the Debug structure with an identification of the activation record of the function executing at a given level. Level 0 is the current running function, whereas level n+1 is the function that has called level n (except for tail calls, which do not count on the stack). When there are no errors, StackDepth returns the Debug structure and nil; Otherwise returns nil and any error.
func (*State) GetSubTable ¶
GetSubTable ensures that stack[index][field] has a table and pushes that table onto the stack.
Returns true if the table already exists at index; otherwise false if the table didn't exist but was created.
See https://www.lua.org/manual/5.3/manual.html#luaL_getsubtable
func (*State) GetTable ¶
GetTable pushes onto the stack the value t[k], where t is the value at the given index and k is the value at the top of the stack.
This function pops the key from the stack, pushing the resulting value in its place. As in Lua, this function may trigger a metamethod for the "index" event (see §2.4).
func (*State) GetUpValue ¶
GetUpValue gets information about the n-th upvalue of the closure at index funcindex. It pushes the upvalue's value onto the stack and returns its name. Returns NULL (and pushes nothing) when the index n is greater than the number of upvalues.
For C functions, this function uses the empty string "" as a name for all upvalues. For Lua functions, upvalues are the external local variables that the function uses, and that are consequently included in its closure.
Upvalues have no particular order, as they are active through the whole function. They are numbered in an arbitrary order.
See https://www.lua.org/manual/5.3/manual.html#lua_getupvalue
func (*State) Insert ¶
Insert moves the top element into the given valid index, shifting up the elements above this index to open space.
This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
func (*State) IsBool ¶
Returns true if the value at the given index is a boolean; otherwise falsse.
See https://www.lua.org/manual/5.3/manual.html#lua_isboolean
func (*State) IsFloat ¶
IsFloat returns true if the value at the given index is an float (that is, the value is a number and is represented as a float), and false otherwise.
func (*State) IsFunc ¶
IsFunc returns true if the value at the given index is a function (either Go or Lua); otherwise returns false.
See https://www.lua.org/manual/5.3/manual.html#lua_isfunction
func (*State) IsGoFunc ¶
IsGoFunc returns true if the value at the given index is a Go function; otherwise returns false.
See https://www.lua.org/manual/5.3/manual.html#lua_iscfunction
func (*State) IsInt ¶
IsInt returns true if the value at the given index is an integer (that is, the value is a number and is represented as an integer), and false otherwise.
See https://www.lua.org/manual/5.3/manual.html#lua_isinteger
func (*State) IsNil ¶
IsNil returns true if the value at the given index is nil, and false otherwise.
func (*State) IsNoneOrNil ¶
IsNoneOrNil returns true if the given index is not valid or if the value at this index is nil and false otherwise.
See https://www.lua.org/manual/5.3/manual.html#lua_isnoneornil
func (*State) IsNumber ¶
IsNumber returns true if the value at the given index is a number or a string convertible to a number, and false otherwise.
func (*State) IsString ¶
IsString returns true if the value at the given index is a string or a number (which is always convertible to a string); otherwise, returns false.
func (*State) IsThread ¶
IsThread returns true if the value at the given index is a thread; otherwise false.
func (*State) Length ¶
Returns the length of the value at the given index. It is equivalent to the ‘\#’ operator in Lua (see [Lua 5.3 Reference Manual](https://www.lua.org/manual/5.3/manual.html#3.4.7)) and may trigger a metamethod for the “length” event (see [Lua 5.3 Reference Manual](https://www.lua.org/manual/5.3/manual.html#2.4)). The result is pushed on the stack.
func (*State) LoadChunk ¶
Load loads a Lua chunk wihtout running it. If there are no errors, Load pushes the compiled chunk as a Lua function on top of the stack, otherwise nothing is pushed and the error is returned.
If the resulting function has upvalues, its first upvalue is set to the value of the global environment stored at index LUA_RIDX_GLOBALS in the registry (see §4.5). When loading main chunks, this upvalue will be the _ENV variable (see §2.2). Other upvalues are initialized with nil.
func (*State) LoadFile ¶
LoadFile uses Load to load a file as a Lua chunk.
See https://www.lua.org/manual/5.3/manual.html#luaL_loadfilex See https://www.lua.org/manual/5.3/manual.html#luaL_loadfile
func (*State) LoadFrom ¶
LoadFrom uses Load to load the Lua chunk from the reader r.
See https://www.lua.org/manual/5.3/manual.html#luaL_loadbuffer See https://www.lua.org/manual/5.3/manual.html#luaL_loadbufferx
func (*State) LoadText ¶
LoadText uses Load to load a string as a Lua chunk.
See https://www.lua.org/manual/5.3/manual.html#luaL_loadstring
func (*State) NewMetaTable ¶
If the registry already has the key name, return false. Otherwise, creates a new table to be used as a metatable for userdata, adds to this new table the pair __name = name, adds to the registry the pair [name] = new table, and returns true. The entry __name is used by some error-reporting functions.
In both cases pushes onto the stack the final value associated with name in the registry.
See https://www.lua.org/manual/5.3/manual.html#luaL_newmetatable
func (*State) NewTable ¶
func (state *State) NewTable()
Creates a new empty table and pushes it onto the stack.
It is equivalent to lua_createtable(L, 0, 0).
func (*State) NewTableSize ¶
Creates a new empty table and pushes it onto the stack. Parameter narr is a hint for how many elements the table will have as a sequence; parameter nrec is a hint for how many other elements the table will have. Lua may use these hints to preallocate memory for the new table. This preallocation is useful for performance when you know in advance how many elements the table will have. Otherwise you can use the function lua_newtable.
func (*State) Next ¶
Next pops a key from the stack, and pushes a key-value pair from the table at the given index (the "next" pair after the given key). If there are no more elements in the table, then Next returns false (and pushes nothing).
While traversing a table, do not call lua.ToString directly on a key, unless you know that the key is actually a string. Recall that lua.ToString may change the value at the given index; this confuses the next call to lua.Next.
See function "next" for the caveats of modifying the table during its traversal.
func (*State) OptInt ¶
OptInt checks if the function argument at index is an integer (or convertible to), and returns the integer; Otherwise, if absent or nil, returns optInt.
This function invokes CheckInt so the caveats of that function apply here.
See https://www.lua.org/manual/5.3/manual.html#luaL_optinteger
func (*State) OptNumber ¶
OptNumber checks if the argument at index is a float and returns the number. Otherwise, if absent or nil, returns optNum.
See https://www.lua.org/manual/5.3/manual.html#luaL_optnumber
func (*State) OptString ¶
OptString checks if the argument at index is a string and returns this string; Otherwise, if absent or nil, returns optStr.
This function invokes CheckString so the caveats of that function apply here.
See https://www.lua.org/manual/5.3/manual.html#pdf-optstring
func (*State) PCall ¶
PCall calls a function in protected mode.
Both nargs and nresults have the same meaning as in lua_call. If there are no errors during the call, lua_pcall behaves exactly like lua_call. However, if there is any error, lua_pcall catches it, pushes a single value on the stack (the error object), and returns an error code. Like lua_call, lua_pcall always removes the function and its arguments from the stack.
If msgh is 0, then the error object returned on the stack is exactly the original error object. Otherwise, msgh is the stack index of a message handler. (This index cannot be a pseudo-index.) In case of runtime errors, this function will be called with the error object and its return value will be the object returned on the stack by lua_pcall.
Typically, the message handler is used to add more debug information to the error object, such as a stack traceback. Such information cannot be gathered after the return of lua_pcall, since by then the stack has unwound.
The lua_pcall function returns one of the following constants (defined in lua.h):
LUA_OK (0): success. LUA_ERRRUN: a runtime error. LUA_ERRMEM: memory allocation error. For such errors, Lua does not call the message handler. LUA_ERRERR: error while running the message handler. LUA_ERRGCMM: error while running a __gc metamethod. For such errors, Lua does not call the message handler (as this kind of error typically has no relation with the function being called).
func (*State) Push ¶
Push pushes any value onto the stack first boxing it by the equivalent Lua value, returning its position in the frame's local stack (top - 1).
func (*State) PushClosure ¶
Pushes a new Go closure onto the stack.
When a Go function is created, it is possible to associate some values with it, thus creating a Go closure (see §4.4); these values are then accessible to the function whenever it is called. To associate values with a Go function, first these values must be pushed onto the stack (when there are multiple values, the first value is pushed first). Then PushClosure is called to create and push the Go function onto the stack, with the argument n telling how many values will be associated with the function. PushClosure also pops these values from the stack.
The maximum value for nups is 255.
When nups is zero, this function creates a light Go function, which is just a pointer to the Go function. In that case, it never raises a memory error.
See https://www.lua.org/manual/5.3/manual.html#lua_pushcclosure
func (*State) PushGlobals ¶
func (state *State) PushGlobals()
PushGlobals pushes the global environment onto the stack.
See https://www.lua.org/manual/5.3/manual.html#lua_pushglobaltable
func (*State) PushIndex ¶
PushIndex pushes a copy of the element at the given index onto the stack.
See https://www.lua.org/manual/5.3/manual.html#lua_pushvalue
func (*State) RawEqual ¶
Returns true if the two values in indices index1 and index2 are primitively equal (that is, without calling the __eq metamethod).
Otherwise returns false. or if any of the indices are not valid.
func (*State) RawGetIndex ¶
Pushes onto the stack the value t[n], where t is the table at the given index.
The access is raw, that is, it does not invoke the __index metamethod.
Returns the type of the pushed value.
func (*State) RawGetPtr ¶
Pushes onto the stack the value t[k], where t is the table at the given index and k is the pointer p represented as a light userdata.
The access is raw; that is, it does not invoke the __index metamethod.
Returns the type of the pushed value.
func (*State) RawLen ¶
RawLen returns the raw "length" of the value at the given index: for strings, this is the string length; for tables, this is the result of the length operator ('#') with no metamethods; for userdata, this is the size of the block of memory allocated for the userdata; for other values, it is 0.
func (*State) RawSet ¶
Similar to lua_settable, but does a raw assignment (i.e., without metamethods).
func (*State) RawSetIndex ¶
Does the equivalent of t[i] = v, where t is the table at the given index and v is the value at the top of the stack.
This function pops the value from the stack.
The assignment is raw, that is, it does not invoke the __newindex metamethod.
func (*State) RawSetPtr ¶
Does the equivalent of t[p] = v, where t is the table at the given index, p is encoded as a light userdata, and v is the value at the top of the stack.
This function pops the value from the stack.
The assignment is raw, that is, it does not invoke __newindex metamethod.
func (*State) Remove ¶
Removes the element at the given valid index, shifting down the elements above this index to fill the gap.
This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
func (*State) Replace ¶
Replace moves the top element into the given valid index without shifting any element (therefore replacing the value at that given index), and then pops the top element.
func (*State) Require ¶
Require loads the module.
If modname is not already present in package.loaded, calls function loader with string modname as an argument and sets the call result in package.loaded[modname], as if that function has been called through require.
If global is true, also stores the module into global modname.
Leaves a copy of the module on the stack.
See https://www.lua.org/manual/5.3/manual.html#luaL_requiref
func (*State) Rotate ¶
rotate rotates the stack elements between the valid index and the top of the stack.
The elements are rotated n positions in the direction of the top, if positive; otherwise -n positions in the direction of the bottom, if negative.
The absolute value of n must not be greater than the size of the slice being rotated.
This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
Let x = AB, where A is a prefix of length 'n'. Then, rotate x n == BA. But BA == (A^r . B^r)^r
func (*State) SetField ¶
Does the equivalent to t[k] = v, where t is the value at the given index and v is the value at the top of the stack.
This function pops the value from the stack.
As in Lua, this function may trigger a metamethod for the "newindex" event (see §2.4).
func (*State) SetFuncs ¶
Registers all functions in the array l (see luaL_Reg) into the table on the top of the stack (below optional upvalues, see next).
When nup is not zero, all functions are created sharing nup upvalues, which must be previously pushed on the stack on top of the library table. These values are popped from the stack after the registration.
func (*State) SetGlobal ¶
Pops a value from the stack and sets it as the new value of global name. func (state *State) SetGlobal(name string, value Value) {
func (*State) SetIndex ¶
Does the equivalent to t[n] = v, where t is the value at the given index and v is the value at the top of the stack.
This function pops the value from the stack.
As in Lua, this function may trigger a metamethod for the "newindex" event (see §2.4).
func (*State) SetMetaTable ¶
SetMetaTable sets the metatable of the object at the top of the stack as the metatable associated with name tname in the registry (see NewMetaTable).
See https://www.lua.org/manual/5.3/manual.html#luaL_setmetatable
func (*State) SetMetaTableAt ¶
Pops a table from the stack and sets it as the new metatable for the value at the given index.
See https://www.lua.org/manual/5.3/manual.html#lua_setmetatable
func (*State) SetTable ¶
SetTable does the equivalent to t[k] = v, where t is the value at the given index, v is the value at the top of the stack, and k is the value just below the top.
This function pops both the key and the value from the stack. As in Lua, this function may trigger a metamethod for the "newindex" event (see §2.4).
func (*State) SetTop ¶
SetTop accepts any index, or 0, and sets the stack top to this index. If the new top is larger than the old one, then the new elements are filled with nil. If index is 0, then all stack elements are removed.
func (*State) SetUpValue ¶
SetUpValue sets the value of a closure's upvalue. It assigns the value at the top of the stack to the upvalue at index and returns its name. It also pops the value from the stack.
Otherwise returns "" (and pops nothing) when upIndex is greater than the number of upvalues.
See https://www.lua.org/manual/5.3/manual.html#lua_setupvalue
func (*State) Status ¶
func (state *State) Status() ThreadStatus
Status returns the status of the thread.
The status can be 0 (LUA_OK) for a normal thread, an error code if the thread finished the execution of a lua_resume with an error, or LUA_YIELD if the thread is suspended.
You can only call functions in threads with status LUA_OK. You can resume threads with status LUA_OK (to start a new coroutine) or LUA_YIELD (to resume a coroutine).
func (*State) TestUserData ¶
TestUserData is equivalent to CheckUserData, except that, when the test fails, it returns nil instead of raising an error.
See https://www.lua.org/manual/5.3/manual.html#luaL_testudata
func (*State) ToBool ¶
ToBool converts the Lua value at the given index to a Go boolean value. Like all tests in Lua, ToBool returns true for any Lua value different from false and nil; otherwise it returns false.
If you want to accept only actual boolean values, use IsBool to test the value's type.
See https://www.lua.org/manual/5.3/manual.html#lua_toboolean
func (*State) ToClosure ¶
ToClosure converts the value at the given index to a Closure.
Otherwise, returns nil.
func (*State) ToFunc ¶
ToFunc converts the value at the given index to a Go function. The value must be a Go function; otherwise, returns nil.
See https://www.lua.org/manual/5.3/manual.html#lua_tocfunction
func (*State) ToInt ¶
ToInt converts the Lua value at the given index to an int64. The Lua value must be an integer, or a number or string convertible to an integer (see §3.4.3); otherwise, returns 0.
See https://www.lua.org/manual/5.3/manual.html#lua_tointeger
func (*State) ToNumber ¶
ToNumber converts the Lua value at the given index to a Number. The Lua value must be a number or a string convertible to a number (see §3.4.3); otherwise, otherwise, returns 0.
func (*State) ToString ¶
ToString converts the Lua value at the given index to a Go string. The Lua value must be a string or a number; otherwise, the function returns ("", false). If the value is a number, then ToString also changes the actual value in the stack to a string. (This change confuses Next(...) when ToString is applied to keys during a table traversal.)
ToString returns a copy of the string inside the Lua state.
See https://www.lua.org/manual/5.3/manual.html#lua_tolstring
func (*State) ToStringMeta ¶
ToStringMeta converts any Lua value at the given index to a C string in a reasonable format. The resulting string is pushed onto the stack and also returned by the function. If len is not NULL, the function also sets *len with the string length.
If the value has a metatable with a __tostring field, then luaL_tolstring calls the corresponding metamethod with the value as argument, and uses the result of the call as its result.
See https://www.lua.org/manual/5.3/manual.html#luaL_tolstring
func (*State) ToTable ¶
ToTable checks and returns the value at the given index if Table otherwise nil.
func (*State) ToThread ¶
ToThread converts the value at the given index to a Lua thread (*State). This value must be a thread; otherwise, the function returns nil.
func (*State) ToUserData ¶
ToUserData returns the value at the given index if type userdata. Otherwise, returns nil.
See https://www.lua.org/manual/5.3/manual.html#lua_touserdata
func (*State) Top ¶
Top returns the index of the top element in the stack.
Because indices start at 1, this result is equal to the number of elements in the stack; in particular, 0 means an empty stack.
func (*State) TypeAt ¶
TypeAt returns the type of the value in the given valid index.
TypeAt returns NilType for a non-valid (but acceptable) index.
Otherwise, TypeAt returns one of:
LUA_TNUMBER LUA_TBOOLEAN LUA_TSTRING LUA_TTABLE LUA_TFUNCTION LUA_TUSERDATA LUA_TTHREAD LUA_TLIGHTUSERDATA
func (*State) UpValueID ¶
UpValueID returns a unique identifier for the upvalue numbered n from the closure at index function.
These unique identifiers allow a program to check whether different closures share upvalues. Lua closures that share an upvalue (that is, that access a same external local variable) will return identical ids for those upvalue indices.
Parameters funcindex and n are as in function lua_getupvalue, but n cannot be greater than the number of upvalues.
See https://www.lua.org/manual/5.3/manual.html#lua_upvalueid
func (*State) UpValueJoin ¶
UpValueJoin makes the n1-th upvalue of the Lua closure at index func1 refer to the n2-th upvalue of the Lua closure at index func2.
See https://www.lua.org/manual/5.3/manual.html#lua_upvaluejoin
func (*State) Version ¶
Returns the address of the version number (a C static variable) stored in the Lua core. When called with a valid lua_State, returns the address of the version used to create that state. When called with NULL, returns the address of the version running the call.
func (*State) Where ¶
Pushes onto the stack a string identifying the current position of the control at level in the call stack. Typically this string has the following format:
chunkname:currentline:
Level 0 is the running function, level 1 is the function that called the running function, etc.
This function is used to build a prefix for error messages.
type ThreadStatus ¶
type ThreadStatus int
ThreadStatus is a Lua thread status.
const ( ThreadOK ThreadStatus = iota // Thread is in success state ThreadYield // Thread is in suspended state ThreadError // Thread finished execution with error )
thread statuses
func (ThreadStatus) String ¶
func (status ThreadStatus) String() string
String returns the canonical string of the thread status.