Functions & closuresReference
gettenv
Represents inspection of a thread environment.
Details#
Returns the global environment table associated with a coroutine. Pass a thread value such as coroutine.create's result. The table is a live reference, not a snapshot, and does not contain the coroutine's local variables. This is gettenv with two t letters, not getenv.
Signature#
gettenv(thread: thread): table?Parameters#
| Parameter | Type | Description |
|---|---|---|
thread | thread | Coroutine whose global environment is requested. |
Returns#
The thread's global table, or nil if unavailable; a non-thread raises an error.
Examples#
Example
local thread = coroutine.create(function() return 1 end)
local environment = gettenv(thread)
print(type(environment)) -- table