Garry's Mod Wiki

Revision Difference

debug.setfenv#560125

<function name="setfenv" parent="debug" type="libraryfunc"> <description>Sets the environment of the passed object.</description>⤶ <description>⤶ <deprecated></deprecated>⤶ ⤶ Sets the environment of the passed object.</description>⤶ <realm>Shared and Menu</realm> <args> <arg name="object" type="table">Object to set environment of</arg> <arg name="env" type="table">Environment to set</arg> </args> <rets> <ret name="" type="table">The object</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 debug.setfenv( Display , newenvironment ) Display() </code> <output> ``` yay ``` </output> </example>