API setfenv

From Warcraft Wiki
Jump to navigation Jump to search

Modifies the environment associated with a function.

f = setfenv(f, env)

Arguments

f
function or number - A function to modify the environment of, or a numeric level of a function on the call stack starting from 1.
env
table - The environment to be assigned to the function.

Returns

f
function - The function whose environment was modified.

Details

  • This function will raise an error if the function to be modified has an existing environment whose metatable has an __environment field set.
  • If this function is called insecurely and the modified function is a Lua function, the modified function will be irrevocably tainted. This will result in all future calls to the function tainting execution.

Patch changes

Dragonflight Patch 10.1.0 (2023-05-02): Now raises an error if the function to be modified has a protected environment.
WoW Icon update.png Patch 1.1.0 (2004-11-07): Added.