Garry's Mod Wiki


setfenv( function location, table enviroment )


Sets the enviroment for a function or a stack level, if a function is passed, the return value will be the function, otherwise nil.


1 function location
The function to set the enviroment for or a number representing stack level.
2 table enviroment
Table to be used as enviroment.


Create a new environment and setfenv Display inside it

local newenvironment = {} function newenvironment.log( msg ) print( msg ) end local function Display() log( "yay" ) end setfenv( Display , newenvironment ) Display()
Output: yay

Page Links

Special Pages



Render Time: 29ms

DB GetPage 3
Generate Html 3
SaveChanges (1) 14
Render Body 0
Render Sidebar 6