Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---ENVIRONMENT ONE---
- x = print --save
- print = function() end
- print("A") --doesn't print anything: print has been set to an empty function
- local environment = getfenv() --save the current environment: a table containing x and print
- --ENVIRONMENT TWO---
- setfenv(1, {print = x, setfenv = setfenv}) --set the new environment, setting print to the saved print
- print("hi") --prints 'hi', print's environment has been changed
- --ENVIRONMENT ONE---
- setfenv(1, environment)
- print("A") --doesn't print anything: revereted back to the original environment
Advertisement
Add Comment
Please, Sign In to add comment