Environment

gettenv

Returns the environment table stored on a Luau thread.

Syntax

gettenv(thread: thread): table
Aliases getstateenv

Arguments

NameTypeDescription
threadthreadLuau thread whose environment table is returned.

Returns

NameTypeDescription
environmenttableEnvironment table for the supplied thread.

Description

Returns the environment table stored on a Luau thread. getstateenv is an alias.

Call it with 1 parameter(s): thread. The argument table explains which values are required and which ones only refine the behavior.

It returns environment (table). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Read the environment table stored on a Luau thread.

local thread = coroutine.create(function()
end)

local env = gettenv(thread)
print(type(env))

local aliasEnv = getstateenv(thread)
print(type(aliasEnv))