Type Function Library (globals) Return value Function Revision Release 2024.3703 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 )
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. The table containing the new environment.