getfenv

Accesses a function or thread environment.

Syntax

Signature
getfenv(Target: (function | thread | number)?) -> table

Aliases

This function has no aliases.

Parameters

ParameterTypeDescription
Target(function | thread | number)?Function, thread, or nonnegative stack level. Defaults to 1.

Returns

TypeDescription
tableLive environment table.

Notes

Returns the environment of a function, thread, or stack level. The default level is 1. Level 0 selects the current thread. For a C closure, returns the calling thread's global environment.

Example

Luau
local Function = function() return Value end
print(getfenv(Function))