ForeverDev

Untitled

Sep 30th, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.55 KB | None | 0 0
  1. ---ENVIRONMENT ONE---
  2. x = print --save
  3. print = function() end
  4. print("A") --doesn't print anything: print has been set to an empty function
  5. local environment = getfenv() --save the current environment: a table containing x and print
  6.  
  7.  
  8. --ENVIRONMENT TWO---
  9. setfenv(1, {print = x, setfenv = setfenv}) --set the new environment, setting print to the saved print
  10. print("hi") --prints 'hi', print's environment has been changed
  11.  
  12.  
  13. --ENVIRONMENT ONE---
  14. setfenv(1, environment)
  15. print("A") --doesn't print anything: revereted back to the original environment
Advertisement
Add Comment
Please, Sign In to add comment