gettenv Synchronous

  • getstateenv

Get the environment table attached to a coroutine. Pass a thread when inspecting another coroutine, or omit it to check your own.

Syntax
Luau
gettenv(target: thread?) -> Table?

Parameters

Function parameters
ParameterTypeDescription
targetthread?Optional coroutine; defaults to the caller.

Returns

Table?

That thread's environment table, or nil when it cannot be read in this VM.

Usage notes

A thread from a different Luau state cannot be inspected through this call.

Example

Example
Luau
local current = coroutine.running()
local env = gettenv(current)
if env then
    print("This thread has an environment table")
end
Kawaii documentation