Skip to main content

Module state

Module state 

Source
Expand description

Global interpreter state.

Manages per-thread (LuaState) and process-wide (GlobalState) Lua state: creation, initialization, teardown, and coroutine lifecycle helpers. Mirrors the responsibilities of Lua’s lstate.c/lstate.h.

C’s LX/LG structs and the fromstate macro exist only to allocate the main thread and global state as one contiguous block via pointer arithmetic; here GlobalState and LuaState are separate heap-allocated values linked via Rc<RefCell<GlobalState>>, so no equivalent is needed.

Structs§

CallInfo
Saved state for a Lua or C call frame.
CallInfoExtra
Payload of CallInfo.u2.
CallInfoFrame
Payload of CallInfo.u.
CallInfoIdx
Index into the call-info stack.
DynLibId
Opaque handle to a dynamically loaded library, allocated by a DynLibLoadHook backend and stored in package._CLIBS.
ExternalRootKey
Stable key for a value pinned in ExternalRootSet.
ExternalRootSet
Values held alive by external Rust handles.
GcHandle
A short-lived handle returned by state.gc() for GC operations.
GcRef
A GC-managed pointer to a Lua collectable object. Newtype over lua_gc::Gc<T> so callers preserve gc.0-shape access while the backend swaps under them.
GlobalState
Process-wide state shared by all Lua threads.
InternedStringMap
The short-string intern table, shaped like C-Lua’s stringtable (lstring.c): power-of-two hash buckets of GcRef<LuaString> chained by Vec instead of u.hnext. Compared to the previous HashMap<Box<[u8]>, GcRef<LuaString>>:
LuaByteHasher
LuaClosureC
LuaClosureLua
LuaProto
LuaState
Per-thread Lua execution state.
LuaString
Lua’s immutable byte-string value.
LuaTable
A Lua table: hybrid array + hash map.
LuaUserData
OsExecuteResult
Result returned by OsExecuteHook, carrying the three values that C-Lua’s luaL_execresult pushes: (boolean|nil, "exit"|"signal", int).
SandboxLimits
Per-runtime sandbox budget, shared by every thread (main + coroutines) via the Rc<RefCell<GlobalState>> they all hold. Every field is a Cell so the VM can charge the budget through the shared Ref it borrows in the count-hook path — no &mut and no write-borrow on the hot path. interval == 0 means inactive; in that case the VM never sets the count-hook mask, so there is zero overhead.
StackIdx
Index into the Lua value stack. Never a pointer or borrow. Stack reallocates; only indices are stable across mutations.
StackIdxConv
Thin wrapper letting stack-indexing methods accept either StackIdx or a raw integer via a single impl Into<StackIdxConv> bound.
StackValue
One slot on the Lua value stack.
ThreadRegistryEntry
One row of GlobalState::threads. Pairs the per-thread LuaState with the canonical GcRef<LuaThread> so every push_thread for the same id shares pointer-identity; the state is wrapped in Rc<RefCell<...>> so resume/yield can mutate the child thread while the parent holds a borrow.
UpVal
A closure upvalue. Open upvalues point at a slot on a thread’s stack (referred to by index, since the stack reallocates). Closed upvalues own the value.
WeakTableEntry

Enums§

DynamicSymbol
Resolved dynamic-library symbol.
F2Imod
Float-to-integer rounding mode (matches C-Lua’s F2Imod).
FinalizerObject
GcKind
Garbage collector operating mode.
LuaCallable
LuaClosure
LuaError
The Lua error type. Carries a LuaValue payload because Lua errors can be any value (typically a string).
LuaStatus
Thread / call status codes.
LuaValue
The dynamically-typed Lua value. Replaces C’s TValue.
OsExecuteReason
Reason a shell command terminated, returned by OsExecuteHook.
TestWarnMode
Output mode for the testC/ltests warning sink.
WarnMode
State of the built-in warning handler, mirroring the warnfoff / warnfon / warnfcont static functions in upstream lauxlib.c.

Constants§

SANDBOX_TRIP_INSTRUCTIONS
Sandbox trip code: the instruction budget reached zero.
SANDBOX_TRIP_MEMORY
Sandbox trip code: GC-tracked memory exceeded the configured ceiling.
SANDBOX_TRIP_NONE
Sandbox trip code: not tripped.

Traits§

Collectable
Marker trait for GC-managed objects.
LuaClosureExt
LuaClosure accessor — nupvalues() reports the upvalue count uniformly.
LuaLClosureRefExt
LuaProtoExt
LuaProto source bytes accessor.
LuaStringRefExt
LuaTableRefExt
GcRef<LuaTable> / GcRef<LuaUserData> field-access helpers, forwarding to the canonical LuaTable/LuaUserData methods through the deref, for use by api.rs and tagmethods.rs.
LuaTypeExt
Extension methods on lua_types::LuaType.
LuaUserDataRefExt
LuaValueExt
Extension methods on LuaValue, kept in lua-vm alongside LuaState rather than in lua_types::value.
StackIdxExt
StackIdx checked-arithmetic helpers. Returns the raw u32 because callers use the result in arithmetic comparisons against other u32 quantities (stack-distance offsets).
TmIndex
Discriminant-to-index conversion for the two parallel TagMethod enums.

Functions§

close
Close the Lua state and free all resources.
close_thread
Close a coroutine thread from the perspective of another thread.
inc_c_stack
Increment the C-call depth counter, checking for overflow.
new_state
Create a new independent Lua state. Returns None only on OOM.
new_thread
Allocate a fresh coroutine LuaState, register it under a new ThreadId, and push the resulting LuaValue::Thread(value) onto state’s stack.
reset_thread
Reset a thread to its base state, closing all to-be-closed variables.
reset_thread_api
Deprecated wrapper for close_thread(L, NULL).
set_c_stack_limit
Deprecated no-op that returns LUAI_MAXCCALLS.
set_versioned_registry_slots
Populate the version-dependent numeric registry slots — the main thread and the globals table — for the current lua_types::LuaVersion.
stack_idx_to_i32
Explicit StackIdxi32 conversion for call sites that need a signed index and would otherwise hit an ambiguous non-primitive-cast error.

Type Aliases§

CpuClockHook
Function-pointer signature for retrieving program CPU time in seconds.
DynLibLoadHook
Function-pointer signature for loading a dynamic library, installed on GlobalState::dynlib_load_hook by the embedder.
DynLibSymbolHook
Function-pointer signature for resolving a symbol in a previously loaded dynamic library, installed on GlobalState::dynlib_symbol_hook.
DynLibUnloadHook
Function-pointer signature for unloading a dynamic library, installed on GlobalState::dynlib_unload_hook.
EntropyHook
Function-pointer signature for host entropy used by default PRNG seeds and table-sort pivot randomisation. Hosts without entropy may leave it unset; the stdlib then uses deterministic fallback values instead of touching OS stubs.
EnvHook
Function-pointer signature for reading a host environment variable.
FileLoaderHook
Function-pointer signature for reading a file’s full contents into memory, installed on GlobalState::file_loader_hook by the embedder.
FileOpenHook
Function-pointer signature for opening a file handle, installed on GlobalState::file_open_hook by the embedder.
FileRemoveHook
Function-pointer signature for removing a file, installed on GlobalState::file_remove_hook by the embedder.
FileRenameHook
Function-pointer signature for renaming a file, installed on GlobalState::file_rename_hook by the embedder.
InputHook
Function-pointer signature for reading bytes from a host-provided input stream, installed on GlobalState::stdin_hook by the embedder.
LocalOffsetHook
Function-pointer signature for the host’s local timezone offset.
LuaByteBuildHasher
LuaCFnPtr
Opaque registry index into GlobalState.c_functions, where the real lua_CFunction (fn(&mut LuaState) -> Result<usize, LuaError>) is stored. Lua-types can’t reference LuaState without a circular dep, so we keep the closure variant type-erased here and resolve through the registry at call time.
LuaCFunction
A Lua-callable function pointer. C: lua_CFunction.
LuaKFunction
Continuation function for yieldable C calls. C: lua_KFunction.
LuaRustFunction
OsExecuteHook
Function-pointer signature for executing a shell command, installed on GlobalState::os_execute_hook by the embedder.
OutputHook
Function-pointer signature for writing bytes to a host-provided output stream, installed on GlobalState::stdout_hook or GlobalState::stderr_hook by the embedder.
ParserHook
Function-pointer signature for the text-source parser, installed on GlobalState::parser_hook by the embedder.
PopenHook
Function-pointer signature for spawning a child process with a connected pipe, installed on GlobalState::popen_hook by the embedder.
TempNameHook
Function-pointer signature for generating a host temporary filename.
UnixTimeHook
Function-pointer signature for retrieving the current Unix time in seconds.