API:setfenv

You can change the environment of a Lua function or the running thread by calling setfenv.

Arguments

 * func
 * function|number - Sets the environment to be used by the given function. func can be a Lua function or a number that specifies the function at that stack level. Level 1 is the function calling setfenv. setfenv returns the given function.
 * _env
 * table - The environment to set the function to. As a special case, when func is 0, setfenv changes the environment of the running thread, and returns no values.

Returns

 * func
 * function - The function in its new environment.

Related Functions

 * getfenv