lua

package
v0.0.0-...-5105380 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: MIT Imports: 15 Imported by: 0

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

View Source
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/"
)
View Source
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"
)
View Source
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"
)
View Source
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
)
View Source
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"
)
View Source
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
)
View Source
const (
	True  = Bool(true)
	False = Bool(false)
)
View Source
const HookKey = 0

The hook table at registry[HookKey] maps threads to their current hook function.

View Source
const None = Nil(0)

Variables

View Source
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 DBG

func DBG(fr *Frame, halt bool)

func IsFloat

func IsFloat(value Value) bool

func IsInt

func IsInt(value Value) bool

func IsNone

func IsNone(value Value) bool

func IsNumber

func IsNumber(value Value) bool

func Truth

func Truth(value Value) bool

func UpValueIndex

func UpValueIndex(index int) int

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 Bool

type Bool bool

func (Bool) String

func (x Bool) String() string

func (Bool) Type

func (x Bool) Type() Type

type CallInfo

type CallInfo struct {
}

CallInfo holds information about a call.

type Callable

type Callable interface {
	Call(args ...Value) ([]Value, error)
}

__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.

func (*Closure) String

func (x *Closure) String() string

func (*Closure) Type

func (x *Closure) Type() Type

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 *Debug) CurrentLine() int

func (*Debug) IsTailCall

func (debug *Debug) IsTailCall() bool

func (*Debug) IsVararg

func (debug *Debug) IsVararg() bool

func (*Debug) LastLineDefined

func (debug *Debug) LastLineDefined() int

func (*Debug) LineDefined

func (debug *Debug) LineDefined() int

func (*Debug) Name

func (debug *Debug) Name() string

func (*Debug) NameWhat

func (debug *Debug) NameWhat() string

func (*Debug) NumParams

func (debug *Debug) NumParams() int

func (*Debug) NumUps

func (debug *Debug) NumUps() int

func (*Debug) ShortSrc

func (debug *Debug) ShortSrc() string

func (*Debug) Source

func (debug *Debug) Source() string

func (*Debug) What

func (debug *Debug) What() string

type Float

type Float float64

func (Float) String

func (x Float) String() string

func (Float) Type

func (x Float) Type() Type

type Frame

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

Frame is the context to execute a function closure.

type Func

type Func func(*State) int

func (Func) String

func (x Func) String() string

func (Func) Type

func (x Func) Type() Type

type HasAdd

type HasAdd interface {
	Add(Value) (Value, error)
}

__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

type HasAnd interface {
	And(Value) (Value, error)
}

__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

type HasConcat interface {
	Concat(Value) (Value, error)
}

__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 HasDiv

type HasDiv interface {
	Div(Value) (Value, error)
}

__div: the division (/) operation. Behavior similar to the addition operation.

type HasEquals

type HasEquals interface {
	Equals(Value) (Value, error)
}

__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

type HasIndex interface {

	//Get(index Value) (Value, error)
	Index(key Value) (Value, error)
}

__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

type HasLength interface {
	Length() (int, error)
}

__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

type HasLessEqual interface {
	LessEqual(Value) (bool, error)
}

__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

type HasLessThan interface {
	LessThan(Value) (bool, error)
}

__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

type HasMinus interface {
	Minus(Value) (Value, error)
}

__unm: the negation (unary -) operation. Behavior similar to the addition operation.

type HasMod

type HasMod interface {
	Mod(Value) (Value, error)
}

__mod: the modulo (%) operation. Behavior similar to the addition operation.

type HasMul

type HasMul interface {
	Mul(Value) (Value, error)
}

__mul: the multiplication (*) operation. Behavior similar to the addition operation.

type HasNewIndex

type HasNewIndex interface {
	SetIndex(key, value Value) error
}

__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

type HasNot interface {
	Not() (Value, error)
}

__bnot: the bitwise NOT (unary ~) operation. Behavior similar to the bitwise AND operation.

type HasOr

type HasOr interface {
	Or(Value) (Value, error)
}

__bor: the bitwise OR (|) operation. Behavior similar to the bitwise AND operation.

type HasPow

type HasPow interface {
	Pow(Value) (Value, error)
}

__pow: the exponentiation (^) operation. Behavior similar to the addition operation.

type HasShl

type HasShl interface {
	Lsh(Value) (Value, error)
}

__shl: the bitwise left shift (<<) operation. Behavior similar to the bitwise AND operation.

type HasShr

type HasShr interface {
	Rsh(Value) (Value, error)
}

__shr: the bitwise right shift (>>) operation. Behavior similar to the bitwise AND operation.

type HasSub

type HasSub interface {
	Sub(Value) (Value, error)
}

__sub: the subtraction (-) operation. Behavior similar to the addition operation.

type HasXor

type HasXor interface {
	Xor(Value) (Value, error)
}

__bxor: the bitwise exclusive OR (binary ~) operation. Behavior similar to the bitwise AND operation.

type HookEvent

type HookEvent uint
const (
	HookCall HookEvent = 1 << iota
	HookRets
	HookLine
	HookCount
	HookTailCall
)

func (HookEvent) String

func (evt HookEvent) String() string

type Int

type Int int64

func (Int) String

func (x Int) String() string

func (Int) Type

func (x Int) Type() Type

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).

const (
	BinaryMode Mode = 1 << iota // Only binary chunks
	TextMode                    // Only text chunks
)

type Nil

type Nil byte

func (Nil) String

func (x Nil) String() string

func (Nil) Type

func (x Nil) Type() Type

type Number

type Number interface {
	Value
	// contains filtered or unexported methods
}

type Object

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

func UserData

func UserData(data interface{}) *Object

func (*Object) String

func (x *Object) String() string

func (*Object) Type

func (x *Object) Type() Type

func (*Object) Value

func (x *Object) Value() interface{}

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

func WithChecks(enable bool) Option

WithChecks returns an Option that instruction a Lua state to perform API checks.

func WithTrace

func WithTrace(enable bool) Option

WithTrace returns an Option that toggles execution tracing.

func WithVerbose

func WithVerbose(enable bool) Option

WithVerbose returns an Option that toggles verbose logging.

type State

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

'per thread' state.

func NewState

func NewState(opts ...Option) *State

NewState returns a new Lua thread state.

func (*State) AbsIndex

func (state *State) AbsIndex(index int) int

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

func (state *State) ArgCheck(cond bool, arg int, msg string)

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

func (state *State) ArgError(arg int, msg string) int

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

func (state *State) Arith(op Op)

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 (>>)

See https://www.lua.org/manual/5.3/manual.html#lua_arith

func (*State) AtPanic

func (state *State) AtPanic(panicFn Func) Func

AtPanic sets a new panic function and returns the old one (see §4.6).

See https://www.lua.org/manual/5.3/manual.html#lua_atpanic

func (*State) Call

func (state *State) Call(args, rets int)

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

func (state *State) CallMeta(index int, event string) bool

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

func (state *State) CheckAny(index int) Value

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

func (state *State) CheckInt(index int) int64

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

func (state *State) CheckNumber(index int) float64

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

func (state *State) CheckStack(needed int) bool

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

func (state *State) CheckString(index int) string

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

func (state *State) CheckType(index int, typ Type)

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

func (state *State) CheckUserData(index int, metaType string) (data interface{})

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.

See https://www.lua.org/manual/5.3/manual.html#lua_close

func (*State) Compare

func (state *State) Compare(op Op, i1, i2 int) bool

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

func (state *State) Concat(n int)

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).

See https://www.lua.org/manual/5.3/manual.html#lua_concat

func (*State) Debug

func (state *State) Debug(halt bool)

func (*State) Dump

func (state *State) Dump(strip bool) []byte

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.

See https://www.lua.org/manual/5.3/manual.html#lua_dump

func (*State) DumpStack

func (state *State) DumpStack(w io.Writer)

DumpStack writes the Lua thread's current stack frame to w.

func (*State) Error

func (state *State) Error() int

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).

See https://www.lua.org/manual/5.3/manual.html#lua_error

func (*State) Errorf

func (state *State) Errorf(format string, args ...interface{}) int

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).

See https://www.lua.org/manual/5.3/manual.html#luaL_error

func (*State) ExecChunk

func (state *State) ExecChunk(filename string, source interface{}, mode Mode) error

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) ExecFile

func (state *State) ExecFile(file string) error

ExecFile uses Exec to load and execute the given file.

See https://www.lua.org/manual/5.3/manual.html#luaL_dofile

func (*State) ExecFrom

func (state *State) ExecFrom(r io.Reader) error

ExecFrom uses Exec to load and execute the Lua chunk from the reader r.

func (*State) ExecText

func (state *State) ExecText(text string) error

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

func (state *State) FileResult(err error, filename string) int

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

func (state *State) GetField(index int, field string) Type

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.

See https://www.lua.org/manual/5.3/manual.html#lua_getfield

func (*State) GetGlobal

func (state *State) GetGlobal(name string) Type

Pushes onto the stack the value of the global name.

Returns the type of that value.

func (*State) GetIndex

func (state *State) GetIndex(index int, entry int64) Type

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.

See https://www.lua.org/manual/5.3/manual.html#lua_geti

func (*State) GetInfo

func (state *State) GetInfo(debug *Debug, options string) error

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).

See https://www.lua.org/manual/5.3/manual.html#lua_getinfo

func (*State) GetMetaField

func (state *State) GetMetaField(index int, event string) Type

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

func (state *State) GetMetaTable(name string) Type

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

func (state *State) GetMetaTableAt(index int) bool

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

func (state *State) GetStack(debug *Debug, depth int) error

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.

See https://www.lua.org/manual/5.3/manual.html#lua_getstack

func (*State) GetSubTable

func (state *State) GetSubTable(index int, field string) bool

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

func (state *State) GetTable(index int) Type

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).

See https://www.lua.org/manual/5.3/manual.html#lua_gettable

func (*State) GetUpValue

func (state *State) GetUpValue(function, index int) (name string)

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

func (state *State) Insert(index int)

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.

See https://www.lua.org/manual/5.3/manual.html#lua_insert

func (*State) IsBool

func (state *State) IsBool(index int) bool

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

func (state *State) IsFloat(index int) bool

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

func (state *State) IsFunc(index int) bool

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

func (state *State) IsGoFunc(index int) bool

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

func (state *State) IsInt(index int) bool

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

func (state *State) IsNil(index int) bool

IsNil returns true if the value at the given index is nil, and false otherwise.

See https://www.lua.org/manual/5.3/manual.html#lua_isnil

func (*State) IsNone

func (state *State) IsNone(index int) bool

IsNone returns true if the given index is not valid, and false otherwise.

See https://www.lua.org/manual/5.3/manual.html#lua_isnone

func (*State) IsNoneOrNil

func (state *State) IsNoneOrNil(index int) bool

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

func (state *State) IsNumber(index int) bool

IsNumber returns true if the value at the given index is a number or a string convertible to a number, and false otherwise.

See https://www.lua.org/manual/5.3/manual.html#lua_isnumber

func (*State) IsString

func (state *State) IsString(index int) bool

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.

See https://www.lua.org/manual/5.3/manual.html#lua_isstring

func (*State) IsThread

func (state *State) IsThread(index int) bool

IsThread returns true if the value at the given index is a thread; otherwise false.

See https://www.lua.org/manual/5.3/manual.html#lua_isthread

func (*State) Length

func (state *State) Length(index int) int

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

func (state *State) LoadChunk(filename string, source interface{}, mode Mode) error

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

func (state *State) LoadFile(file string) error

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

func (state *State) LoadFrom(r io.Reader) error

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

func (state *State) LoadText(text string) error

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) Log

func (state *State) Log(args ...interface{})

func (*State) Logf

func (state *State) Logf(format string, args ...interface{})

func (*State) Main

func (state *State) Main(args ...string) error

func (*State) NewMetaTable

func (state *State) NewMetaTable(name string) bool

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

func (state *State) NewTableSize(narr, nrec int)

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

func (state *State) Next(index int) (more bool)

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.

See https://www.lua.org/manual/5.3/manual.html#lua_next

func (*State) OptInt

func (state *State) OptInt(index int, optInt int64) int64

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

func (state *State) OptNumber(index int, optNum float64) float64

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

func (state *State) OptString(index int, optStr string) string

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

func (state *State) PCall(args, rets, msgh int) (err error)

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).

See https://www.lua.org/manual/5.3/manual.html#lua_pcall

func (*State) Pop

func (state *State) Pop() Value

Pop pops the top value from the Lua thread's current frame stack.

func (*State) PopN

func (state *State) PopN(n int) []Value

PopN pops the top n values from the Lua thread's current frame stack.

func (*State) Preload

func (state *State) Preload(module string, loader Func)

Preload preloads a Lua module into the package.preload table.

func (*State) Push

func (state *State) Push(any interface{}) int

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

func (state *State) PushClosure(fn Func, nups uint8)

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

func (state *State) PushIndex(index int)

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

func (state *State) RawEqual(i1, i2 int) bool

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.

See https://www.lua.org/manual/5.3/manual.html#lua_rawequal

func (*State) RawGet

func (state *State) RawGet(index int) Type

Similar to lua_gettable, but does a raw access (i.e., without metamethods).

See https://www.lua.org/manual/5.3/manual.html#lua_rawget

func (*State) RawGetIndex

func (state *State) RawGetIndex(index, entry int) Type

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.

See https://www.lua.org/manual/5.3/manual.html#lua_rawgeti

func (*State) RawGetPtr

func (state *State) RawGetPtr(index int, udata *Object) Type

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.

See https://www.lua.org/manual/5.3/manual.html#lua_rawgetp

func (*State) RawLen

func (state *State) RawLen(index int) int

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.

See https://www.lua.org/manual/5.3/manual.html#lua_rawlen

func (*State) RawSet

func (state *State) RawSet(index int)

Similar to lua_settable, but does a raw assignment (i.e., without metamethods).

See https://www.lua.org/manual/5.3/manual.html#lua_rawset

func (*State) RawSetIndex

func (state *State) RawSetIndex(index, entry int)

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.

See https://www.lua.org/manual/5.3/manual.html#lua_rawseti

func (*State) RawSetPtr

func (state *State) RawSetPtr(index int, udata *Object)

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.

See https://www.lua.org/manual/5.3/manual.html#lua_rawsetp

func (*State) Register

func (state *State) Register(name string, fn Func)

Register sets the Go function fn as the new value of global name.

func (*State) Remove

func (state *State) Remove(index int)

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.

See https://www.lua.org/manual/5.3/manual.html#lua_remove

func (*State) Replace

func (state *State) Replace(index int)

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.

See https://www.lua.org/manual/5.3/manual.html#lua_replace

func (*State) Require

func (state *State) Require(module string, loader Func, global bool)

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

func (state *State) Rotate(index, n int)

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

See https://www.lua.org/manual/5.3/manual.html#lua_rotate

func (*State) SetField

func (state *State) SetField(index int, field string)

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).

See https://www.lua.org/manual/5.3/manual.html#lua_setfield

func (*State) SetFuncs

func (state *State) SetFuncs(funcs map[string]Func, nups uint8)

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

func (state *State) SetGlobal(name string)

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

func (state *State) SetIndex(index int, entry int64)

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).

See https://www.lua.org/manual/5.3/manual.html#lua_seti

func (*State) SetMetaTable

func (state *State) SetMetaTable(name string)

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

func (state *State) SetMetaTableAt(index int)

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

func (state *State) SetTable(index int)

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).

See https://www.lua.org/manual/5.3/manual.html#lua_settable

func (*State) SetTop

func (state *State) SetTop(top int)

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.

See https://www.lua.org/manual/5.3/manual.html#lua_settop

func (*State) SetUpValue

func (state *State) SetUpValue(fnIndex, upIndex int) (name string)

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).

See https://www.lua.org/manual/5.3/manual.html#lua_status

func (*State) String

func (ls *State) String() string

String returns a printable string of the current executing thread state.

func (*State) TestUserData

func (state *State) TestUserData(index int, metaType string) (data interface{})

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

func (state *State) ToBool(index int) bool

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

func (state *State) ToClosure(index int) *Closure

ToClosure converts the value at the given index to a Closure.

Otherwise, returns nil.

func (*State) ToFunc

func (state *State) ToFunc(index int) Func

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

func (state *State) ToInt(index int) int64

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

func (state *State) ToNumber(index int) float64

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.

See https://www.lua.org/manual/5.3/manual.html#lua_tonumber

func (*State) ToString

func (state *State) ToString(index int) string

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

func (state *State) ToStringMeta(index int) string

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

func (state *State) ToTable(index int) Table

ToTable checks and returns the value at the given index if Table otherwise nil.

func (*State) ToThread

func (state *State) ToThread(index int) *State

ToThread converts the value at the given index to a Lua thread (*State). This value must be a thread; otherwise, the function returns nil.

See https://www.lua.org/manual/5.3/manual.html#lua_tothread

func (*State) ToUserData

func (state *State) ToUserData(index int) *Object

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

func (state *State) Top() int

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.

See https://www.lua.org/manual/5.3/manual.html#lua_gettop

func (*State) TryFloat

func (state *State) TryFloat(index int) (float64, bool)

func (*State) TryInt

func (state *State) TryInt(index int) (int64, bool)

func (*State) TryNumber

func (state *State) TryNumber(index int) (Number, bool)

func (*State) TryString

func (state *State) TryString(index int) (string, bool)

func (*State) TypeAt

func (state *State) TypeAt(index int) Type

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

func (state *State) UpValueID(function, index int) interface{}

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

func (state *State) UpValueJoin(func1, n1, func2, n2 int)

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

func (state *State) Version() *float64

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.

See https://www.lua.org/manual/5.3/manual.html#lua_version

func (*State) Where

func (state *State) Where(level int)

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.

See https://www.lua.org/manual/5.3/manual.html#luaL_where

func (*State) XMove

func (state *State) XMove(dst *State, n int)

XMove exchanges values between different threads of the same state.

This function pops N values from the state's stack, and pushes them onto the state dst's stack.

See https://www.lua.org/manual/5.3/manual.html#lua_xmove

type String

type String string

func (String) String

func (x String) String() string

func (String) Type

func (x String) Type() Type

type Table

type Table interface {
	Value

	Length() int
	Index(index Value) Value
	ForEach(func(key, value Value))
}

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.

type Type

type Type int
const (
	NoneType Type = iota
	NilType
	BoolType
	NumberType
	StringType
	FuncType
	UserDataType
	ThreadType
	TableType
)

func (Type) String

func (id Type) String() string

type Value

type Value interface {
	// String returns the canonical string of this value.
	String() string

	// Type returns the type name of this value.
	//
	// Types:
	// nil
	// boolean
	// number
	// string
	// function
	// userdata
	// thread
	// table
	Type() Type
}

func ValueOf

func ValueOf(state *State, value interface{}) Value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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