Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. env = {}
  2.  
  3. --[[----------------------------------------------------/
  4. /-------------------------------------------------------/
  5. /----------------------env.lua--------------------------/
  6. /----------------------By ZenX2-------------------------/
  7. /-------------------------------------------------------/
  8. /-----This allows you to make unloadable lua files.-----/
  9. /-----Yippee! just create a new environment, and--------/
  10. /-----set it as the current in every file using it.-----/
  11. /-------------------------------------------------------/
  12. /------------------------------------------------------]]
  13.  
  14. function env.Create(e)
  15.     local ng = {}
  16.     setmetatable(ng, {__index = e or _G})
  17.     return ng
  18. end
  19.  
  20. function env.Set(e, f)
  21.     setfenv(f or 2, e)
  22. end
  23.  
  24. function env.Unload(f)
  25.     setfenv(f or 2, env.G)
  26. end
  27.  
  28. function env.GetGlobal()
  29.  
  30.     return getfenv(2) --should return the normal global environment
  31.  
  32. end
  33.  
  34. env.G = env.GetGlobal() --shortcut!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement