getreg
Returns the Luau registry table used internally by the VM.
function getreg(): { [any]: any }Synopsis
How it works
Returns the Luau registryLua registryA hidden global table at pseudo-index LUA_REGISTRYINDEX, used by C code to store persistent references. Contains _LOADED (module cache), lua_ref references, thread refs, and callback storage. Shared across all threads in the VM. table — a hidden global table used by the VM to store internal references. The registry holds references to running coroutines, loaded modules (via
_LOADED), signal connections, and C-side references created with lua_ref().Structure
The registryLua registryA hidden global table at pseudo-index LUA_REGISTRYINDEX, used by C code to store persistent references. Contains _LOADED (module cache), lua_ref references, thread refs, and callback storage. Shared across all threads in the VM. is an array-like table of mixed types. Common entries include:
- Functions: callbacks registered for events or connections
- Tables: module return values, _LOADED_LOADEDA table in the Lua registry that maps module names to their return values. When require() loads a ModuleScript, the result is cached here. Subsequent require() calls return the cached value instead of re-executing. cache
- Threads: active coroutines
Usage
Find and cancel a running coroutine from the registry
local my_thread = task.spawn(function()
while task.wait(1) do print("tick") end
end)
task.wait(0.1)
for _, v in pairs(getreg()) do
if v == my_thread then
task.cancel(v)
print("Thread found and cancelled")
break
end
endReturns
{ [any]: any } The Luau registry table containing all VM-registered object references.
Handle with care
The registry contains internal VM state. Modifying it incorrectly can crash the Lua VM. Treat as read-only unless you know exactly what you are doing.