Garry's Mod Wiki

debug.setfenv

  table debug.setfenv( table object, table env )

Description

We advise against using this. It may be changed or removed in a future update.

Sets the environment of the passed object.

Arguments

1 table object
Object to set environment of
2 table env
Environment to set

Returns

1 table
The object

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 debug.setfenv( Display , newenvironment ) Display()
Output:
yay