Documentation ¶
Index ¶
- Constants
- func ArgCheck(L State, cond bool, numarg int, extramsg string) bool
- func ArgError(L State, numarg int, extramsg string) int
- func Call(L State, nargs, nresults int)
- func CallMeta(L State, obj int, e string) int
- func CheckStack(L State, sz int) int
- func CheckString(L State, numarg int) string
- func Close(L State)
- func Concat(L State, n int)
- func CreateTable(L State, narr int, nrec int)
- func Equal(L State, index1, index2 int) bool
- func Error(L State) int
- func GC(L State, what GCMode, data int) int
- func GetFEnv(L State, idx int)
- func GetField(L State, idx int, k string)
- func GetGCCount(L State) int
- func GetGlobal(L State, s string)
- func GetMetaField(L State, obj int, e string) bool
- func GetMetaTableFor(L State, name string)
- func GetMetatable(L State, objindex int) bool
- func GetRegistry(L State)
- func GetTable(L State, idx int)
- func GetTop(L State) int
- func Insert(L State, idx int)
- func IsBoolean(L State, n int) bool
- func IsCFunction(L State, idx int) bool
- func IsFunction(L State, n int) bool
- func IsLightUserdata(L State, n int) bool
- func IsNil(L State, n int) bool
- func IsNone(L State, n int) bool
- func IsNoneOrNil(L State, n int) bool
- func IsNumber(L State, idx int) bool
- func IsString(L State, idx int) bool
- func IsTable(L State, n int) bool
- func IsThread(L State, n int) bool
- func IsUserdata(L State, idx int) bool
- func LessThan(L State, index1, index2 int) bool
- func LoadString(L State, s string) int
- func NewTable(L State)
- func NewUserdata(L State, sz int) uintptr
- func Next(L State, idx int) bool
- func ObjLen(L State, idx int) int
- func OpenBase(L State) int
- func OpenBit(L State) int
- func OpenDebug(L State) int
- func OpenFfi(L State) int
- func OpenIo(L State) int
- func OpenJit(L State) int
- func OpenLibs(L State)
- func OpenMath(L State) int
- func OpenOs(L State) int
- func OpenPacakge(L State) int
- func OpenString(L State) int
- func OpenStringBuffer(L State) int
- func OpenTable(L State) int
- func OptString(L State, numarg int, d string) string
- func PCall(L State, nargs, nresults, errfunc int) int
- func Pop(L State, n int)
- func ProfileDumpStack(L State, fmt string, depth int, len *uint) string
- func ProfileStart(L State, mode string, cb ProfileCallback, data uintptr)
- func ProfileStop(L State)
- func PushBoolean(L State, b bool)
- func PushClosure(L State, fn CFunction, n int)
- func PushFString(L State, fmt string, args ...any) string
- func PushInteger(L State, n Integer)
- func PushLString(L State, s string, l int)
- func PushLightUserdata(L State, p uintptr)
- func PushNil(L State)
- func PushNumber(L State, n Number)
- func PushString(L State, s string)
- func PushThread(L State) bool
- func PushValue(L State, idx int)
- func RawEqual(L State, index1, index2 int) bool
- func RawGet(L State, idx int)
- func RawGetI(L State, idx, n int)
- func RawSet(L State, idx int)
- func RawSetI(L State, idx, n int)
- func Register(L State, libname string, l []LReg)
- func Remove(L State, idx int)
- func Replace(L State, idx int)
- func Resume(L State, narg int) int
- func SetFEnv(L State, idx int) bool
- func SetField(L State, idx int, k string)
- func SetGlobal(L State, s string)
- func SetMetatable(L State, objindex int) int
- func SetMode(L State, idx int, mode JitMode) bool
- func SetTable(L State, idx int)
- func SetTop(L State, idx int)
- func Status(L State) int
- func Strlen(L State, i int) int
- func ToBoolean(L State, idx int) bool
- func ToCString(gostring string) []byte
- func ToGoString(cstr []byte) string
- func ToGoStringPtr(cstr *byte, len int) string
- func ToLString(L State, idx int, len *uint) string
- func ToPointer(L State, idx int) uintptr
- func ToString(L State, idx int) string
- func ToUserdata(L State, idx int) uintptr
- func TypeError(L State, narg int, tname string) int
- func TypeName(L State, tp T) string
- func TypeNameOf(L State, idx int) string
- func UpvalueIndex(i int) int
- func XMove(from, to State, n int)
- func Yield(L State, nresults int) int
- type CFunction
- type GCMode
- type Integer
- type JitMode
- type LReg
- type Number
- type ProfileCallback
- type State
- type T
Constants ¶
const ( JitVersion = "LuaJIT 2.1.1724232689" JitCopyright = "Copyright (C) 2005-2023 Mike Pall" )
const ( ModeOff = JitMode(0x0000) ModeOn = JitMode(0x0100) ModeFlush = JitMode(0x0200) ModeMask = JitMode(0x00ff) )
const ( CoroutineLibName = "coroutine" MathLibName = "math" StringLibName = "string" TableLibName = "table" IoLibName = "io" OsLibName = "os" LoadLibName = "package" DbLibName = "debug" BitLibName = "bit" JitLibName = "jit" FfiLibName = "ffi" )
const ( Version = "Lua 5.1" Release = "Lua 5.1.4" VersionNum = 501 Copyright = "Copyright (C) 1994-2008 Lua.org, PUC-Rio" Authors = "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" )
const ( MultRet = -1 RegistryIndex = -10000 EnvironIndex = -10001 GlobalsIndex = -10002 )
const ( StatusOk = 0 StatusYield = 1 )
const ( ErrRun = 2 // A runtime error ErrSyntax = 3 // Syntax error during pre-compilation ErrMem = 4 // Memory allocation error ErrErr = 5 // Error while running the error handler function )
const ( TNone = T(-1) TNil = T(0) TBoolean = T(1) TLightUserdata = T(2) TNumber = T(3) TString = T(4) TTable = T(5) TFunction = T(6) TUserdata = T(7) TThread = T(8) )
const ( GCStop = GCMode(0) // Stops the garbage collector GCRestart = GCMode(1) // Restarts the garbage collector GCCollect = GCMode(2) // Performs a full garbage collection cycle GCCount = GCMode(3) // Returns the current amount of memory (in Kbytes) in use GCCountB = GCMode(4) // Returns the remainder of dividing the current memory in use by 1024 GCStep = GCMode(5) // Performs an incremental step of garbage collection GCSetPause = GCMode(6) // Sets data as the new value for the pause of the collector GCSetStepMul = GCMode(7) // Sets data as the new value for the step multiplier of the collector GCIsRunning = GCMode(9) // Returns if the garbage collector is running )
const (
ErrFile = ErrErr + 1 // A file cannot be open/read
)
const (
MinStack = 20
)
const Signature = "\033Lua"
Mark for precompiled code.
Variables ¶
This section is empty.
Functions ¶
func ArgCheck ¶
ArgCheck checks whether cond is true. If not, raises an error with the following message, where func is retrieved from the call stack:
bad argument #<narg> to <func> (<extramsg>)
func ArgError ¶
ArgError raises an error with the following message:
bad argument #<narg> to <func> (<extramsg>)
Where func is retrieved from the call stack. This function never returns, but it is an idiom to use it in [CFunction]s as a return.
func CheckStack ¶
CheckStack ensures that there are at least extra free stack slots in the stack. It returns false if it cannot grow the stack to that size. This function never shrinks the stack; if the stack is already larger than the new size, it is left unchanged.
func CheckString ¶
CheckString checks whether the function argument numarg is a string and returns its string.
func Close ¶
func Close(L 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
func Concat ¶
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.
func CreateTable ¶
CreateTable creates a new empty table and pushes it onto the stack. The new table has space pre-allocated for narr array elements and nrec non-array elements.
This pre-allocation is useful when you know exactly how many elements the table will have. Otherwise you can use the function NewTable.
func Equal ¶
Equals returns true if the two values in acceptable indices index1 and index2 are equal, following the semantics of the Lua == operator (that is, may call metamethods). Otherwise returns false.
Also returns false if any of the indices is non valid.
func Error ¶
Error generates a Lua error.
The error message (which can actually be a Lua value of any type) must be on the stack top.
func GetField ¶
GetField pushes onto the stack the value t[k], where t is the value at the given valid index.
func GetGCCount ¶
GetGCCount returns the current amount of memory (in Kbytes) in use by Lua.
func GetMetaField ¶
GetMetaField pushes onto the stack the field e from the metatable of the object at index obj. If the object does not have a metatable, or if the metatable does not have this field, returns false and pushes nothing.
func GetMetaTableFor ¶
GetMetaTableFor pushes onto the stack the metatable associated with name in the registry.
func GetMetatable ¶
GetMetatable pushes onto the stack the metatable of the value at the given acceptable index. If the index is not valid, or if the value does not have a metatable, the function returns false and pushes nothing on the stack.
func GetRegistry ¶
func GetRegistry(L State)
func GetTable ¶
GetTable pushes onto the stack the value t[k], where t is the value at the given valid index and k is the value at the top of the stack.
func GetTop ¶
GetTop 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 (and so 0 means an empty stack).
func Insert ¶
Insert moves the top element into the given valid index, shifting up the elements above this index to open space. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
func IsCFunction ¶
IsCFunction returns true if the value at the given acceptable index is a C function, and false otherwise.
func IsFunction ¶
IsTable returns if the value at the given acceptable index is a function.
func IsLightUserdata ¶
IsLightUserdata returns if the value at the given acceptable index is a userdata (either full or light).
func IsNone ¶
IsNone returns if the given acceptable index is not valid (that is, it refers to an element outside the current stack).
func IsNoneOrNil ¶
IsNoneOrNil returns if the given acceptable index is not valid (that is, it refers to an element outside the current stack) or if the value at this index is nil.
func IsNumber ¶
IsNumber returns true if the value at the given acceptable index is a number or a string convertible to a number, and false otherwise.
func IsString ¶
IsString returns true if the value at the given acceptable index is a string or a number (which is always convertible to a string), and false otherwise.
func IsUserdata ¶
IsUserdata returns true if the value at the given acceptable index is a userdata (either full or light), and false otherwise.
func LessThan ¶
LessThan returns true if the value at acceptable index index1 is smaller than the value at acceptable index index2, following the semantics of the Lua < operator (that is, may call metamethods). Otherwise returns false.
Also returns false if any of the indices is non valid.
func LoadString ¶
LoadString loads a string as a Lua chunk.
This function returns the same results as Load.
func NewTable ¶
func NewTable(L State)
NewTable creates a new empty table and pushes it onto the stack.
func NewUserdata ¶
NewUserdata allocates a new block of memory with the given size, pushes onto the stack a new full userdata with the block address, and returns this address.
func 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).
func ObjLen ¶
ObjLen returns the "length" of the value at the given acceptable index:
- For strings, this is the string length
- For tables, this is the result of the length operator ('#');
- For userdata, this is the size of the block of memory allocated for the userdata;
- For other values, it is 0.
func OpenLibs ¶
func OpenLibs(L State)
OpenLibs opens all standard Lua libraries into the given state.
func OpenPacakge ¶
OpenPackage opens the package library into the given state.
func OpenString ¶
OpenString opens the string library into the given state.
func OpenStringBuffer ¶
OpenStringBuilder opens the string builder library into the given state.
func PCall ¶
PCall calls a function in protected mode.
If errfunc is 0, then the error message returned on the stack is exactly the original error message.
Otherwise, errfunc is the stack index of an error handler function. (In the current implementation, this index cannot be a pseudo-index.) In case of runtime errors, this function will be called with the error message and its return value will be the message returned on the stack by PCall.
func ProfileDumpStack ¶
ProfileDumpStack allows taking stack dumps in an effecient manner.
func ProfileStart ¶
func ProfileStart(L State, mode string, cb ProfileCallback, data uintptr)
ProfileStart starts the profiler.
func PushBoolean ¶
PushBoolean pushes a boolean value with value b onto the stack.
func PushFString ¶
PushFString pushes onto the stack a formatted string and returns the string.
The conversion specifiers are quite restricted. There are no flags, widths, or precisions. The conversion specifiers can only be:
- '%%' (inserts a '%' in the string)
- '%s' (inserts a zero-terminated string, with no size restrictions)
- '%f' (inserts a Number)
- '%p' (inserts a pointer as a hexadecimal numeral)
- '%d' (inserts an Integer)
- '%c' (inserts an Integer as a character)
func PushInteger ¶
PushInteger pushes a number with value n onto the stack.
func PushLString ¶
PushLString pushes a string with the value s and the size len onto the stack.
Lua makes (or reuses) an internal copy of the given string.
func PushLightUserdata ¶
PushLightUserdata pushes a light userdata onto the stack.
func PushNumber ¶
PushNumber pushes a number with value n onto the stack.
func PushString ¶
PushString pushes a string with the value s onto the stack.
Lua makes (or reuses) an internal copy of the given string.
func PushThread ¶
PushThread pushes the thread represented by L onto the stack. Returns true if this thread is the main thread of its state.
func RawEqual ¶
RawEqual returns true if the two values in acceptable indices index1 and index2 are primitively equal (that is, without calling metamethods). Otherwise returns false.
Also returns false if any of the indices are non valid.
func RawGetI ¶
RawGetI pushes onto the stack the value t[n], where t is the value at the given valid index.
The access is raw; that is, it does not invoke metamethods.
func RawSetI ¶
RawSetI does the equivalent of t[n] = v, where t is the value at the given valid 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 metamethods.
func Register ¶
Register opens a library.
When called with libname equal to nil, it simply registers all functions in the list l into the table on the top of the stack.
func Remove ¶
Remove removes the element at the given valid index, shifting down the elements above this index to fill the gap. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
func Replace ¶
Replace moves the top element into the given position (and pops it), without shifting any element (therefore replacing the value at the given position).
func SetFEnv ¶
SetFEnv pops a table from the stack and sets it as the new environment for the value at the given index.
If the value at the given index is neither a function nor a thread nor a userdata, SetFEnv returns false. Otherwise it returns true.
func SetField ¶
SetField does the equivalent to t[k] = v, where t is the value at the given valid 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.
func SetMetatable ¶
SetMetatable pops a table from the stack and sets it as the new metatable for the value at the given acceptable index.
func SetMode ¶
SetMode allows control of the VM.
'idx' is expected to be 0 or a stack index.
'mode' specifies the mode, which is 'or'ed with a flag. The flag can be:
- ModeOff to turn a feature off
- ModeOn to turn a feature on
- ModeFlush to flush cached code.
func SetTable ¶
SetTable does the equivalent to t[k] = v, where t is the value at the given valid 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.
func SetTop ¶
SetTop accepts any acceptable 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 Status ¶
Status returns the status of the thread L.
The status can be StatusOk for a normal thread, an error code if the thread finished its execution with an error, or StatusYield if the thread is suspended.
func ToCString ¶
ToCString creates a null-terminated byte slice from a Go string.
The resulting slice is a new copy.
func ToGoString ¶
ToGoString creates a Go string from a null-terminated byte slice.
The resulting string is a new copy.
func ToGoStringPtr ¶
ToGoStringPtr creates a Go string from a byte pointer and length.
The resulting string is a new copy.
func ToLString ¶
ToLString converts the Lua value at the given acceptable index to a string. If len is not nil, it also sets len with the string length.
func ToPointer ¶
ToPointer converts the value at the given acceptable index to a generic pointer. The value can be a userdata, a table, a thread, or a function.
Different objects will give different pointers. There is no way to convert the pointer back to its original value.
func ToUserdata ¶
ToUserdata returns the block address of the value at the given acceptable index if it's a full userdata. If the value is a light userdata, ToUserdata returns its pointer.
func TypeError ¶
TypeError generates an error with a message like the following:
location: bad argument narg to 'func' (tname expected, got rt)
Where location is produced by Where, func is the name of the current function, and rt is the type name of the actual argument
func TypeNameOf ¶
TypeNameOf returns the name of the type of the value at the given index.
func UpvalueIndex ¶
Types ¶
type CFunction ¶
CFunction represents a function used to interact with the Lua VM.
func ToCFunction ¶
ToCFunction converts a value at the given acceptable index to a CFunction.
type GCMode ¶
type GCMode int32
GCMode represents a mode used to interact with the Lua garbage collector.
type Integer ¶
type Integer int64 // Integer represents a Lua integer.
type JitMode ¶
type JitMode int32
JitMode represents a mode used to interact with the jit compiler.
const ( ModeEngine JitMode = iota ModeDebug ModeFunc ModeAllFunc ModeAllSubFunc ModeTrace ModeWrapCFunc = JitMode(0x10) ModeMax = ModeWrapCFunc + 1 )
type ProfileCallback ¶
ProfileCallback represents a function used for profiling.
type State ¶
type State uintptr
State represents a pointer to a Lua state.
func NewThread ¶
NewThread creates a new thread, pushes it on the stack, and returns a new Lua state that represents this new thread. The new state returned by this function shares with the original state all global objects (such as tables), but has an independent execution stack.
There is no explicit function to close or to destroy a thread. Threads are subject to garbage collection, like any Lua object.