Documentation
¶
Overview ¶
Package api defines the public Go API for the Lua VM.
This is the Go equivalent of C's lua_* functions (lapi.c) and luaL_* auxiliary functions (lauxlib.c). It provides a stack-based API for manipulating Lua state from Go. All standard library implementations use this API.
Reference: .analysis/09-standard-libraries.md §1-§2
auxiliary.go — Auxiliary library functions (luaL_* equivalents).
call.go — Call and load operations (Call, PCall, Load, DoFile, DoString).
coroutine_impl.go — Coroutine API implementation (NewThread, Resume, Yield, Status).
debug_impl.go — Debug interface implementation (GetInfo, GetLocal, SetLocal, hooks).
gc_impl.go — GC integration (gcMarkSweep, GCCollect, clearStaleStack, finalizers).
impl.go — Core Lua API implementation (State, stack ops, push, type checks, conversions).
nodekey_init.go registers the ReconstructObj callback for table node key reconstruction. This breaks the import cycle: the table package can't import state/closure, but needs to return properly-typed TValues from nodeKey().
table_ops.go — Table access operations (GetTable, SetTable, GetField, SetField, Next, Len).
userdata_ops.go — Userdata and upvalue access operations.
Index ¶
- Constants
- func DebugGetProto(L *State) *object.Proto
- func UpvalueIndex(i int) int
- func WrapCFunction(f CFunction) object.TValue
- type ArithOp
- type CFunction
- type CompareOp
- type DebugInfo
- type GCWhat
- type State
- func (L *State) AbsIndex(idx int) int
- func (L *State) ArgCheck(cond bool, arg int, extraMsg string)
- func (L *State) ArgError(arg int, extraMsg string) int
- func (L *State) ArgExpected(cond bool, arg int, tname string)
- func (L *State) Arith(op ArithOp)
- func (L *State) Call(nArgs, nResults int)
- func (L *State) CallK(nArgs, nResults int, ctx int, k state.KFunction)
- func (L *State) CheckAny(idx int)
- func (L *State) CheckInteger(idx int) int64
- func (L *State) CheckNumber(idx int) float64
- func (L *State) CheckOption(idx int, def string, opts []string) int
- func (L *State) CheckStack(n int) bool
- func (L *State) CheckString(idx int) string
- func (L *State) CheckType(idx int, tp object.Type)
- func (L *State) CheckUdata(idx int, tname string)
- func (L *State) ClearHookFields()
- func (L *State) Close()
- func (L *State) CloseSlot(idx int)
- func (L *State) Compare(idx1, idx2 int, op CompareOp) bool
- func (L *State) Concat(n int)
- func (L *State) Copy(fromIdx, toIdx int)
- func (L *State) CreateTable(nArr, nRec int)
- func (L *State) DoFile(filename string) error
- func (L *State) DoString(code string) error
- func (L *State) Dump(strip bool) []byte
- func (L *State) Error() int
- func (L *State) Errorf(format string, args ...interface{}) int
- func (L *State) GC(what GCWhat, args ...int) int
- func (L *State) GCAgeName(idx int) string
- func (L *State) GCCollect()
- func (L *State) GCColorName(idx int) string
- func (L *State) GCObjectAt(idx int) *object.GCHeader
- func (L *State) GCStateName() string
- func (L *State) GCStepAPI() bool
- func (L *State) GCTotalBytes() int64
- func (L *State) GetField(idx int, key string) object.Type
- func (L *State) GetFuncProtoInfo(idx int) (source, shortSource, what string, lineDefined, lastLine, nups, nparams int, ...)
- func (L *State) GetGCMode() string
- func (L *State) GetGCParam(name string) int64
- func (L *State) GetGlobal(name string) object.Type
- func (L *State) GetI(idx int, n int64) object.Type
- func (L *State) GetIUserValue(idx int, n int) object.Type
- func (L *State) GetInfo(what string, ar *DebugInfo) bool
- func (L *State) GetLClosure(idx int) *closure.LClosure
- func (L *State) GetLocal(ar *DebugInfo, n int) string
- func (L *State) GetMetafield(idx int, field string) bool
- func (L *State) GetMetatable(idx int) bool
- func (L *State) GetStack(level int) (*DebugInfo, bool)
- func (L *State) GetSubTable(idx int, fname string) bool
- func (L *State) GetTable(idx int) object.Type
- func (L *State) GetTop() int
- func (L *State) GetUpvalue(funcIdx, n int) (string, bool)
- func (L *State) GetUserdataObj(idx int) *object.Userdata
- func (L *State) HasCallFrames() bool
- func (L *State) HookActive() bool
- func (L *State) HookCount() int
- func (L *State) HookMask() int
- func (L *State) Insert(idx int)
- func (L *State) IsBoolean(idx int) bool
- func (L *State) IsCFunction(idx int) bool
- func (L *State) IsFunction(idx int) bool
- func (L *State) IsGCInFinalizer() bool
- func (L *State) IsGCRunning() bool
- func (L *State) IsInteger(idx int) bool
- func (L *State) IsNil(idx int) bool
- func (L *State) IsNone(idx int) bool
- func (L *State) IsNoneOrNil(idx int) bool
- func (L *State) IsNumber(idx int) bool
- func (L *State) IsString(idx int) bool
- func (L *State) IsTable(idx int) bool
- func (L *State) IsUserdata(idx int) bool
- func (L *State) IsYieldable() bool
- func (L *State) Len(idx int)
- func (L *State) LenI(idx int) int64
- func (L *State) Load(code string, name string, mode string) int
- func (L *State) LoadFile(filename string, mode string) int
- func (L *State) MemoryLimit() int64
- func (L *State) NewLib(funcs map[string]CFunction)
- func (L *State) NewMetatable(tname string) bool
- func (L *State) NewTable()
- func (L *State) NewThread() *State
- func (L *State) NewUserdata(size int, nUV int) *object.Userdata
- func (L *State) Next(idx int) bool
- func (L *State) OptInteger(idx int, def int64) int64
- func (L *State) OptNumber(idx int, def float64) float64
- func (L *State) OptString(idx int, def string) string
- func (L *State) PCall(nArgs, nResults, msgHandler int) int
- func (L *State) Pop(n int)
- func (L *State) PushBoolean(b bool)
- func (L *State) PushCClosure(f CFunction, n int)
- func (L *State) PushCFunction(f CFunction)
- func (L *State) PushCFunctionSame(tv object.TValue)
- func (L *State) PushFString(format string, args ...interface{}) string
- func (L *State) PushFail()
- func (L *State) PushFuncFromDebug(ar *DebugInfo) bool
- func (L *State) PushGlobalTable()
- func (L *State) PushInteger(n int64)
- func (L *State) PushLightUserdata(p interface{})
- func (L *State) PushNil()
- func (L *State) PushNumber(n float64)
- func (L *State) PushString(s string) string
- func (L *State) PushTValue(v object.TValue)
- func (L *State) PushThread() bool
- func (L *State) PushValue(idx int)
- func (L *State) RawEqual(idx1, idx2 int) bool
- func (L *State) RawGet(idx int) object.Type
- func (L *State) RawGetI(idx int, n int64) object.Type
- func (L *State) RawGetP(idx int, p uintptr) object.Type
- func (L *State) RawLen(idx int) int64
- func (L *State) RawSet(idx int)
- func (L *State) RawSetI(idx int, n int64)
- func (L *State) RawSetP(idx int, p uintptr)
- func (L *State) Ref(t int) int
- func (L *State) Remove(idx int)
- func (L *State) Replace(idx int)
- func (L *State) Require(modname string, openf CFunction, global bool)
- func (L *State) Resume(from *State, nArgs int) (int, int)
- func (L *State) Rotate(idx, n int)
- func (L *State) RunGCUntilState(targetState byte) string
- func (L *State) SetField(idx int, key string)
- func (L *State) SetFuncs(funcs map[string]CFunction, nUp int)
- func (L *State) SetGCMode(mode string) string
- func (L *State) SetGCParam(name string, value int64) int64
- func (L *State) SetGCStopped(stopped bool)
- func (L *State) SetGlobal(name string)
- func (L *State) SetHookFields(mask, count int)
- func (L *State) SetHookMarker()
- func (L *State) SetI(idx int, n int64)
- func (L *State) SetIUserValue(idx int, n int) bool
- func (L *State) SetLocal(ar *DebugInfo, n int) string
- func (L *State) SetMemoryLimit(limit int64) int64
- func (L *State) SetMetatable(idx int)
- func (L *State) SetStatus(status int)
- func (L *State) SetTable(idx int)
- func (L *State) SetTableMeta(idx int)
- func (L *State) SetTop(idx int)
- func (L *State) SetUpvalue(funcIdx, n int) (string, bool)
- func (L *State) SetWarnF(f func(ud any, msg string, tocont bool), ud any)
- func (L *State) Status() int
- func (L *State) StringToNumber(s string) int
- func (L *State) SweepStrings()
- func (L *State) TableSizes(idx int) (int, int)
- func (L *State) TestUdata(idx int, tname string) bool
- func (L *State) ToBoolean(idx int) bool
- func (L *State) ToClose(idx int)
- func (L *State) ToGoFunction(idx int) CFunction
- func (L *State) ToInteger(idx int) (int64, bool)
- func (L *State) ToNumber(idx int) (float64, bool)
- func (L *State) ToPointer(idx int) string
- func (L *State) ToString(idx int) (string, bool)
- func (L *State) ToThread(idx int) *State
- func (L *State) ToUserdata(idx int) interface{}
- func (L *State) TolString(idx int) string
- func (L *State) TrackAlloc(n int64)
- func (L *State) Type(idx int) object.Type
- func (L *State) TypeError(arg int, tname string) int
- func (L *State) TypeName(tp object.Type) string
- func (L *State) Unref(t int, ref int)
- func (L *State) UpvalueId(funcIdx, n int) interface{}
- func (L *State) UpvalueJoin(funcIdx1, n1, funcIdx2, n2 int)
- func (L *State) Warning(msg string, tocont bool)
- func (L *State) Where(level int)
- func (L *State) XMove(to *State, n int)
- func (L *State) Yield(nResults int) int
- func (L *State) YieldK(nResults int, ctx int, k CFunction) int
Constants ¶
const ( RIdxMainThread = 3 // LUA_RIDX_MAINTHREAD RIdxGlobals = 2 // LUA_RIDX_GLOBALS — the _G table )
Registry keys for well-known values.
const ( StatusOK = 0 StatusYield = 1 StatusErrRun = 2 StatusErrSyntax = 3 StatusErrMem = 4 StatusErrErr = 5 StatusErrFile = 6 // file I/O error (mirrors LUA_ERRFILE) )
Status codes
const MultiRet = -1
MultiRet signals "return all results".
const NoRef = -2
NoRef is the "no reference" value.
const RefNil = -1
RefNil is the reference value for nil.
const (
RegistryIndex = -1000000 - 1000 // LUA_REGISTRYINDEX
)
const TypeNone object.Type = 0xFF
TypeNone is the type for invalid indices.
Variables ¶
This section is empty.
Functions ¶
func DebugGetProto ¶
DebugGetProto returns the Proto of the LClosure at top of stack (for testing).
func UpvalueIndex ¶
UpvalueIndex returns the pseudo-index for upvalue i (1-based).
func WrapCFunction ¶
WrapCFunction wraps a CFunction into a state.CFunction + TValue. The caller can cache the result and pass it to PushCFunctionSame.
Types ¶
type CFunction ¶
CFunction is the type for Go functions callable from Lua. It receives the Lua state and returns the number of results pushed.
type DebugInfo ¶
type DebugInfo struct {
Source string // source of the chunk
ShortSrc string // short source (for error messages)
LineDefined int // line where definition starts
LastLineDefined int // line where definition ends
CurrentLine int // current line
Name string // function name (if known)
NameWhat string // "global", "local", "method", "field", ""
What string // "Lua", "C", "main"
NUps int // number of upvalues
NParams int // number of parameters
IsVararg bool // is a vararg function
IsTailCall bool // is a tail call
ExtraArgs int // number of extra arguments (vararg)
FTransfer int // index of first transferred value (for call/return hooks)
NTransfer int // number of transferred values (for call/return hooks)
CI interface{} // internal: *state.CallInfo
ThreadState interface{} // internal: *state.LuaState (set by GetStack)
}
DebugInfo holds debug information about a function activation.
type State ¶
type State struct {
// Internal fields set during construction — not exported.
// The implementation file will define these.
Internal any // *state.LuaState (avoids circular import)
// Writer is the custom output writer for print() and related functions.
// If nil, os.Stdout is used. Set by pkg/lua.State.SetWriter().
// Stored here (not on pkg/lua.State) so it survives wrapFunction which
// creates fresh pkg/lua.State wrappers sharing the same api.State.
Writer io.Writer
// FileSystem is the custom filesystem for file loading (require, dofile,
// loadfile). If nil, the real OS filesystem is used.
// Stored here (not on pkg/lua.State) so it survives wrapFunction which
// creates fresh pkg/lua.State wrappers sharing the same api.State.
FileSystem fs.FS
// Ctx is the Go context for cancellation/timeout.
// Stored here (not on pkg/lua.State) so it survives wrapFunction which
// creates fresh pkg/lua.State wrappers sharing the same api.State.
// If nil, context.Background() should be assumed by callers.
Ctx context.Context
// GlobalSearcher is set by pkg/lua to enable global module registry lookup.
// It receives a module name and returns a CFunction loader, or nil if not found.
// This indirection avoids circular imports between pkg/lua and internal/stdlib.
GlobalSearcher func(name string) CFunction
// UserData stores arbitrary Go values associated with string keys.
// Stored here (not on pkg/lua.State) so it survives wrapFunction which
// creates fresh pkg/lua.State wrappers sharing the same api.State.
UserData map[string]any
}
State is the public Lua state handle. It wraps the internal LuaState and provides the stack-based API.
func (*State) ArgCheck ¶
ArgCheck checks a condition for argument arg. If cond is false, raises an error.
func (*State) ArgError ¶
ArgError raises an error for argument arg. Mirrors: luaL_argerror in lauxlib.c
func (*State) ArgExpected ¶
ArgExpected checks that argument arg has the expected type name.
func (*State) CallK ¶
CallK calls a function with a continuation for yielding. If k is non-nil and the coroutine is yieldable, the call is made yieldable and the continuation k will be invoked upon resume after a yield. Otherwise behaves identically to Call (non-yieldable). Mirrors: lua_callk in lapi.c
func (*State) CheckInteger ¶
CheckInteger checks that argument at idx is an integer and returns it. If the value is a float that can't be represented as an int64, raises "has no integer representation" error. If the value is not a number at all, raises "number expected" error. Mirrors: luaL_checkinteger → luaO_str2intX in lauxlib.c / lobject.c.
func (*State) CheckNumber ¶
CheckNumber checks that argument at idx is a number and returns it.
func (*State) CheckOption ¶
CheckOption checks that the argument at idx is a string matching one of the options. Returns the index of the matched option.
func (*State) CheckStack ¶
CheckStack ensures at least n free stack slots.
func (*State) CheckString ¶
CheckString checks that argument at idx is a string and returns it.
func (*State) CheckUdata ¶
CheckUdata checks that the value at idx is a userdata with metatable matching registry[tname]. Raises a type error if not. Mirrors: luaL_checkudata in lauxlib.c
func (*State) ClearHookFields ¶
func (L *State) ClearHookFields()
ClearHookFields clears all hook fields.
func (*State) Close ¶
func (L *State) Close()
Close releases all resources associated with the state.
func (*State) CloseSlot ¶
CloseSlot closes the to-be-closed variable at the given index and sets the slot to nil. The index must be the last marked to-be-closed slot. Uses CLOSEKTOP semantics: does not reset L.Top (preserves stack above). Mirrors: lua_closeslot in lapi.c:206-214
func (*State) CreateTable ¶
CreateTable pushes a new table with pre-allocated space.
func (*State) Dump ¶
Dump dumps the function at the top of the stack as a binary chunk. If strip is true, debug information is removed. Returns the binary chunk bytes, or nil if the value is not a Lua function. Mirrors: lua_dump in lapi.c
func (*State) GCAgeName ¶
GCAgeName returns the generational age name for the GC object at idx. Returns "" if the value is not a GC object.
func (*State) GCCollect ¶
func (L *State) GCCollect()
GCCollect runs a full Lua mark-and-sweep GC cycle, then calls all pending __gc finalizers. This is the V5 GC entry point. Mirrors C Lua's luaC_fullgc + callallpendingfinalizers. NOT safe to call during VM execution — use gcMarkSweep for periodic GC.
func (*State) GCColorName ¶
GCColorName returns "white", "gray", or "black" for the GC object at idx. Returns "" if the value is not a GC object.
func (*State) GCObjectAt ¶
GCObjectAt returns the GCHeader for the GC-collectable object at stack index idx. Returns nil if the value is not a GC object (nil, boolean, number, light userdata).
func (*State) GCStateName ¶
GCStateName returns the name of the current GC state. Maps GCState byte constants to their C Lua names.
func (*State) GCStepAPI ¶
GCStepAPI runs a bounded GC step for collectgarbage("step"). In incremental mode: runs bounded SingleSteps. In generational mode: runs a minor (young) collection. Returns true if a full GC cycle completed during this step. Mirrors C Lua's lua_gc(LUA_GCSTEP).
func (*State) GCTotalBytes ¶
GCTotalBytes returns the Lua-level allocation counter (bytes). Mirrors C Lua's gettotalbytes(g) for collectgarbage("count").
func (*State) GetFuncProtoInfo ¶
func (L *State) GetFuncProtoInfo(idx int) (source, shortSource, what string, lineDefined, lastLine, nups, nparams int, isVararg, ok bool)
GetFuncProtoInfo inspects a Lua closure at stack index `idx` and returns its Proto metadata. For C functions returns defaults with ok=false.
func (*State) GetGCMode ¶
GetGCMode returns the current GC mode string ("incremental" or "generational"). Defaults to "incremental" if not set.
func (*State) GetGCParam ¶
GetGCParam returns the current value of a GC parameter. For pause/stepmul/stepsize, reads from the direct GlobalState fields. For other params, falls back to the GCParams map.
func (*State) GetI ¶
GetI pushes t[n] where t is at idx. Mirrors lua_geti: handles __index metamethods for non-table types and for table keys that are not found.
func (*State) GetIUserValue ¶
GetIUserValue pushes the n-th user value of the userdata at idx onto the stack. Returns the type of the pushed value, or TypeNone if invalid. For non-full-userdata or invalid n, pushes nil and returns TypeNone. Mirrors: lua_getiuservalue in lapi.c
func (*State) GetInfo ¶
GetInfo fills debug info fields specified by what string. Mirrors: lua_getinfo in lapi.c
func (*State) GetLClosure ¶
GetLClosure returns the LClosure at the given stack index, or nil if not a Lua closure.
func (*State) GetMetafield ¶
GetMetafield pushes the metamethod field from the metatable of the value at idx. Returns true if found (value pushed), false if not (nothing pushed).
func (*State) GetMetatable ¶
GetMetatable pushes the metatable of the value at idx.
func (*State) GetSubTable ¶
GetSubTable ensures that t[fname] is a table, creating it if needed. Returns true if the table already existed.
func (*State) GetUpvalue ¶
GetUpvalue pushes the value of upvalue n of the closure at funcIdx. Returns (name, true) if upvalue exists, ("", false) if not. C closure upvalues are always named "" (empty string).
func (*State) GetUserdataObj ¶
GetUserdataObj returns the full Userdata struct at idx, or nil if not userdata.
func (*State) HasCallFrames ¶
HasCallFrames returns true if the thread has call frames above the base CI. Mirrors: lua_getstack(L, 0, &ar) in C Lua — returns true when ci != &L->base_ci.
func (*State) HookActive ¶
HookActive returns true if any hooks are set.
func (*State) IsCFunction ¶
IsCFunction returns true if the value is a C/Go function.
func (*State) IsFunction ¶
IsFunction returns true if the value is a function.
func (*State) IsGCInFinalizer ¶
IsGCInFinalizer returns true if a __gc finalizer is currently executing.
func (*State) IsGCRunning ¶
IsGCRunning returns true if GC is not stopped.
func (*State) IsNoneOrNil ¶
IsNoneOrNil returns true if the index is not valid or the value is nil.
func (*State) IsUserdata ¶
IsUserdata returns true if the value is a userdata.
func (*State) IsYieldable ¶
IsYieldable returns true if the running coroutine can yield.
func (*State) Len ¶
Len pushes the length of the value at idx. Mirrors lua_len: calls luaV_objlen which handles __len metamethods.
func (*State) LenI ¶
LenI returns the length of the value at idx as an integer (calls __len if needed).
func (*State) LoadFile ¶
LoadFile loads a Lua file without executing it. Pushes the compiled chunk as a function on success. Returns a status code (StatusOK on success, or an error code).
func (*State) MemoryLimit ¶
MemoryLimit returns the current memory limit (0 = no limit).
func (*State) NewMetatable ¶
NewMetatable creates a new metatable in the registry with the given name. If the registry already has a table with that name, pushes it and returns false. Otherwise creates a new table, stores it in registry[tname], and returns true. Mirrors: luaL_newmetatable in lauxlib.c
func (*State) NewThread ¶
NewThread creates a new Lua thread (coroutine), pushes it on the stack, and returns a *State representing the new thread. Mirrors: lua_newthread in lstate.c
func (*State) NewUserdata ¶
NewUserdata creates a new full userdata with nUV user values and pushes it. Returns the Userdata object. size is ignored (Go manages memory).
func (*State) OptInteger ¶
OptInteger returns the integer at idx, or def if nil/none.
func (*State) PushCClosure ¶
PushCClosure pushes a Go function as a closure with n upvalues.
func (*State) PushCFunction ¶
PushCFunction pushes a Go function as a light C function (no upvalues).
func (*State) PushCFunctionSame ¶
PushCFunctionSame pushes a pre-wrapped C function value. Unlike PushCFunction, which creates a new wrapper each call, this pushes the exact same TValue each time. Use for stateless iterators (e.g., ipairs) where identity must be preserved.
func (*State) PushFString ¶
PushFString pushes a formatted string.
func (*State) PushFail ¶
func (L *State) PushFail()
PushFail pushes a "fail" value (false in Lua 5.4+).
func (*State) PushFuncFromDebug ¶
PushFuncFromDebug pushes the function associated with a DebugInfo onto the stack. Returns true if successful, false if the CI is nil or invalid.
func (*State) PushGlobalTable ¶
func (L *State) PushGlobalTable()
PushGlobalTable pushes the global table.
func (*State) PushLightUserdata ¶
func (L *State) PushLightUserdata(p interface{})
PushLightUserdata pushes a light userdata.
func (*State) PushString ¶
PushString pushes a string. Returns the string.
func (*State) PushTValue ¶
PushTValue pushes an existing TValue directly onto the stack. Unlike PushString etc., this preserves object identity (pointer).
func (*State) PushThread ¶
PushThread pushes the running thread onto its own stack. Returns true if the thread is the main thread.
func (*State) RawGetP ¶
RawGetP does t[p] where p is a light userdata pointer key. Pushes the result. Mirrors: lua_rawgetp in lapi.c
func (*State) RawSetP ¶
RawSetP does t[p] = v where p is a light userdata pointer key. v is the value at the top of the stack (popped). Mirrors: lua_rawsetp in lapi.c
func (*State) Ref ¶
Ref creates a reference in the table at idx (luaL_ref). Pops the top value and stores it in the table, returning an integer key. If the value is nil, returns RefNil (-1) and pops the value without storing.
func (*State) Require ¶
Require calls openf to load a module, stores in package.loaded. If the module is already in package.loaded, pushes the cached value. Mirrors luaL_requiref in lauxlib.c.
func (*State) Resume ¶
Resume starts or resumes a coroutine. Returns (status, nresults) matching lua_resume in ldo.c. status is StatusOK (finished) or StatusYield (suspended) on success, or an error status on failure.
func (*State) RunGCUntilState ¶
RunGCUntilState advances the GC state machine by calling SingleStep until it reaches the target state. Returns the state name reached. Used by T.gcstate("statename") in the test library.
func (*State) SetGCMode ¶
SetGCMode sets the GC mode and returns the previous mode string. Actually switches the GC between incremental and generational modes.
func (*State) SetGCParam ¶
SetGCParam sets a GC parameter and returns the previous value. For pause/stepmul/stepsize, updates the direct GlobalState fields used by the debt-based GC pacer.
func (*State) SetGCStopped ¶
SetGCStopped sets or clears the GCStopped flag (collectgarbage "stop"/"restart").
func (*State) SetHookFields ¶
SetHookFields sets the hook mask, count, and enable flag on the internal state.
func (*State) SetHookMarker ¶
func (L *State) SetHookMarker()
SetHookMarker sets a non-nil marker in Hook to indicate hooks are active.
func (*State) SetIUserValue ¶
SetIUserValue sets the n-th user value of the userdata at idx to the value at the top of the stack. Pops the value. Returns false if the operation fails. Mirrors: lua_setiuservalue in lapi.c
func (*State) SetMemoryLimit ¶
SetMemoryLimit sets the maximum memory (in bytes) that Lua objects can use. 0 means no limit. Returns the previous limit. When the limit is exceeded, TrackAllocation attempts a GC cycle and then panics with StatusErrMem if still over limit.
func (*State) SetMetatable ¶
SetMetatable pops a table and sets it as metatable for value at idx.
func (*State) SetStatus ¶
SetStatus sets the thread status (used by test library for panic simulation).
func (*State) SetTableMeta ¶
SetTableMeta does t[k] = v with __newindex metamethod support. Used by testC's settable instruction. Separate from SetTable to avoid Go call stack overflow in deep metamethod chains (events.lua).
func (*State) SetTop ¶
SetTop sets the stack top to idx. Fills with nil if growing. When shrinking, closes any to-be-closed variables above the new top. Mirrors: lua_settop in lapi.c:179-203
func (*State) SetUpvalue ¶
SetUpvalue sets upvalue n of the closure at funcIdx from the top value. Returns (name, true) if upvalue exists, ("", false) if not.
func (*State) SetWarnF ¶
SetWarnF sets the warning handler function. Mirrors C Lua's lua_setwarnf (lapi.c).
func (*State) StringToNumber ¶
StringToNumber tries to convert a string to a number and pushes it. Returns the length+1 on success, 0 on failure.
func (*State) SweepStrings ¶
func (L *State) SweepStrings()
SweepStrings removes dead interned strings from the string table.
func (*State) TableSizes ¶
TableSizes returns the array part length and hash part capacity for a table at idx. Returns (0, 0) if the value is not a table.
func (*State) TestUdata ¶
TestUdata checks if the value at idx is a userdata with metatable matching registry[tname]. Returns true if it matches, false otherwise. Does not modify the stack. Mirrors: luaL_testudata in lauxlib.c
func (*State) ToClose ¶
ToClose marks the value at the given index as to-be-closed. Its __close metamethod will be called when the slot goes out of scope. Mirrors: lua_toclose in lapi.c:1288-1296
func (*State) ToGoFunction ¶
ToGoFunction returns the Go function at idx, or nil.
func (*State) ToThread ¶
ToThread converts the value at the given index to a *State (thread). Returns nil if the value is not a thread.
func (*State) ToUserdata ¶
func (*State) TolString ¶
TolString converts the value at idx to a string, using __tostring metamethod if present. Pushes the result on the stack and returns it.
func (*State) TrackAlloc ¶
TrackAlloc adds n bytes to the Lua-level allocation counter.
func (*State) TypeError ¶
TypeError raises a type error for argument arg. Mirrors: luaL_typeerror in lauxlib.c — checks __name, then light userdata, then standard name.
func (*State) Unref ¶
Unref frees a reference in the table at idx (luaL_unref). Sets t[ref] = nil and adds ref to the free list at t[0].
func (*State) UpvalueId ¶
UpvalueId returns a unique identifier for the upvalue n of the closure at funcIdx. This can be used to check if two closures share the same upvalue. Returns nil if the upvalue doesn't exist. Mirrors: lua_upvalueid in lapi.c
func (*State) UpvalueJoin ¶
UpvalueJoin makes the n1-th upvalue of the closure at funcIdx1 refer to the n2-th upvalue of the closure at funcIdx2. Mirrors: lua_upvaluejoin in lapi.c
func (*State) Warning ¶
Warning issues a warning message through the registered handler. tocont=true means the message is a continuation (more parts follow). Mirrors C Lua's lua_warning (lapi.c).
func (*State) XMove ¶
XMove moves n values from L's stack to to's stack. Mirrors: lua_xmove in lapi.c