Environment
Reach the global environments of Lynx, Roblox and running scripts.
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(): tablegetgenv returns the Lynx global environment, where scripts can store shared functions and values.
Returns
tableModule environment table for the selected VM.
Example
getreg
getreg(): tablegetreg returns the registry table for the current Luau VM.
Returns
tableCurrent VM registry.
Example
gettenv
gettenv(thread: thread? = coroutine.running()): tablegettenv 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
tableThe global environment of the selected same-VM thread.
Example
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
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
Written for Lynx 0.747
Something unclear? Tell us on Discord