EnvironmentOverview
getgenv
Provides the module's global environment entry point.
Details#
Returns the module's shared global environment table. Values placed here can be shared by chunks using that environment. This is not an operating-system environment-variable API: getenv is not a registered spelling. For a coroutine use gettenv; ordinary Luau getfenv concerns a function or stack frame.
Examples#
Example
local env = getgenv()
local previous = env.docsExample
env.docsExample = "hello"
print(getgenv().docsExample) -- hello
env.docsExample = previousFunction environment versus thread and shared environments
local chunk = assert(loadstring("return answer"))
setfenv(chunk, { answer = 42 })
print(chunk()) -- 42
print(getfenv(chunk).answer) -- function environment
print(type(gettenv(coroutine.create(function() end)))) -- thread environment
print(type(getgenv())) -- module shared environment