Garry's Mod Wiki

Revision Difference

Global.setfenv#544793

<function name="setfenv" parent="Global" type="libraryfunc"> <description>Sets the enviroment for a function or a stack level, if a function is passed, the return value will be the function, otherwise nil.</description> <description>Sets the enviroment for a function or a stack level.</description> <realm>Shared and Menu</realm> <args> <arg name="location" type="function">The function to set the enviroment for or a number representing stack level.</arg> <arg name="enviroment" type="table">Table to be used as enviroment.</arg> </args> <rets>⤶ <ret name="" type="function">The function passed, otherwise nil.</ret>⤶ </rets>⤶ </function> <example> <description>Create a new environment and setfenv Display inside it</description> <code> local newenvironment = {} function newenvironment.log( msg ) print( msg ) end local function Display() log( "yay" ) end setfenv( Display , newenvironment ) Display() </code> <output> ``` yay ``` </output> </example>