BrinkerVII

A hacky print toggle module

Oct 18th, 2017
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.59 KB | None | 0 0
  1. local HANDLE_FUNCTIONS = {
  2.     Enabled = true,
  3.    
  4.     On = (function(this)
  5.         this.Enabled = true
  6.     end),
  7.    
  8.     Off = (function(this)
  9.         this.Enabled = false
  10.     end),
  11. }
  12.  
  13. HackyPrintToggle = {
  14.     CreateHandle = (function(this)
  15.         local handle = {}
  16.         for k, v in pairs(HANDLE_FUNCTIONS) do
  17.             handle[k] = v
  18.         end
  19.        
  20.         return handle
  21.     end),
  22.    
  23.     Inject = (function(this, env)
  24.         local targetEnv = env or getfenv(2)
  25.         local handle = this:CreateHandle()
  26.        
  27.         targetEnv.print = function(...)
  28.             if handle.Enabled then
  29.                 print(...)
  30.             end
  31.         end
  32.        
  33.         return handle
  34.     end)
  35. }
  36.  
  37. return HackyPrintToggle
Add Comment
Please, Sign In to add comment