Garry's Mod Wiki

setfenv

setfenv

  function setfenv( function location, table enviroment )

Description

Sets the enviroment for a function or a stack level.

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.

Returns

1 function
The function passed, otherwise nil.

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

Special Pages


Wikis

?

Render Time: 23ms

DB GetPage 2
Generate Html 5
SaveChanges (1) 5
Render Body 0
Render Sidebar 8