Type Function
Library (globals)
Return value Function
Revision 2017.3111
Keywords setfenv, environment, globals
See also getfenv()


Sets the environment — or the table where Lua keeps all its global variables — to be used by the given function.

This function returns the same function that is passed as the first argument.


setfenv( f, table )
f (required)

Function or Number. If f is a function, setfenv() sets the environment for that function. If a number is specified, the environment for the function at that stack level is set. Number 1 means the current function, number 2 means the function calling the current function, and so on. As a special case, when set to 0, setfenv() changes the environment of the running thread, in which case nothing is returned.

table (required)

Table. The table containing the new environment.