Garry's Mod Wiki

setfenv

setfenv( function location, table enviroment )

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.

Arguments

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.

Example

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


Wikis

?

Render Time: 67ms

DB GetPage 35
Generate Html 6
SaveChanges (1) 10
Render Body 0
Render Sidebar 12