Environment

Reach the global environments of Lynx, Roblox and running scripts.

5 functionssUNC 100%Lynx 0.747

Environment functions provide access to globals, the registry and garbage-collectable values. Use getrenv to access the native runtime environment. Actor states can have their own global tables and registries.

getgenv

getgenv(): table

getgenv returns the Lynx global environment, where scripts can store shared functions and values.

Returns

table

Module environment table for the selected VM.

Example

getgenv().ExampleSetting = true
print(getgenv().ExampleSetting)

getreg

getreg(): table

getreg returns the registry table for the current Luau VM.

Returns

table

Current VM registry.

Example

print(rawequal(getreg(), debug.getregistry()))

gettenv

gettenv(thread: thread? = coroutine.running()): table

gettenv returns the global environment of a thread in the current Luau VM.

Parameters

threadthread?
Optional.The same-VM thread whose global environment to retrieve. Omit or pass nil to select the caller. Default coroutine.running().

Returns

table

The global environment of the selected same-VM thread.

Example

local thread = coroutine.create(function() end)
local environment = gettenv(thread)
print(type(environment))

getgc

getgc(includeTables: boolean? = false): {any}

getgc returns a list of live garbage-collectable values in the current VM. The list includes functions and userdata, and can optionally include tables.

Also available as get_gc, get_garbagecollectable, get_garbage_collector and get_gc_objects.

Parameters

includeTablesboolean?
Optional.Whether tables are included alongside functions and userdata. Default false.

Returns

{any}

A snapshot table whose weak entries may disappear during garbage collection.

Example

local objects = getgc(true)
print(getrawmetatable(objects).__mode)
for _, object in pairs(objects) do
if type(object) == "function" then print(object) end
end

filtergc

filtergc(kind: string, options: table, returnOne: boolean? = false): {any} | any?

filtergc finds functions or tables that match a set of search conditions. You can return all matches or stop at the first matching value.

Also available as filter_gc.

Parameters

kindstring
Function or table search selector.
optionstable
Search conditions for the selected kind; see the fields below.
returnOneboolean?
Optional.Return one value rather than an array. Default false.

Returns

{any} | any?

Matching array, or first match/nil when returnOne is true.

Example

local matches = filtergc("function", {
Name = "example",
IgnoreExecutor = false,
})
for _, fn in ipairs(matches) do print(debug.getinfo(fn).source) end
Name
Type/defaultstring
Exact debug name.
Hash
Type/defaultstring
SHA-384 prototype hash, as returned by getfunctionhash.
StartLine
Type/defaultnumber
Luau prototype definition line.
Environment
Type/defaulttable
Same environment table identity.
Constants
Type/default{any}
Requested constant values; Luau functions only.
Upvalues
Type/default{any}
Requested upvalue values; Luau functions only.
IgnoreExecutor
Type/defaultboolean = true
Exclude module-marked closures.
IgnoreSyn
Type/defaultboolean
Legacy fallback when IgnoreExecutor is not a boolean.
Metatable
Typetable
Same metatable identity.
Keys
Type{any}
Every listed value is an existing key.
Values
Type{any}
Listed values appear among table values.
KeyValuePairs
Typetable
Every supplied key/value association appears.