Threads are created sharing the environment of the creating thread. Userdata and C functions are created sharing the environment of the creating C function. Non-nested Lua functions (created by , or ) are created sharing the environment of the creating thread. Nested Lua functions are created sharing the environment of the creating Lua function.
Environments associated with threads are called global environments. They are used as the default environment for threads and non-nested Lua functions created by the thread and can be directly accessed by C code (see §3.3).
Environments associated with Lua functions are used to resolve all accesses to global variables within the function (see ). They are used as the default environment for nested Lua functions created by the function.