setfenv

From Garry's Mod
Jump to: navigation, search
 setfenv( )

Contents

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

function location

The function to set the enviroment for or a number representing stack level.

Arguments

table enviroment

Table to be used as enviroment.

Examples

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
Personal tools
Navigation