Advertisement
FocusedWolf

Event.Hook Workaround

Sep 10th, 2011
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. //New version that's simpler: http://pastebin.com/38jjPhnx
  2.  
  3. class 'UnitTestManager' (GUIScript)
  4.  
  5. local this
  6. function UnitTestManager:Initialize()
  7.  
  8.     this = self
  9.  
  10.     self.tests = {}
  11.  
  12. end
  13.  
  14. function UnitTestManager:Uninitialize()
  15.  
  16.     self.tests = nil
  17.  
  18. end
  19.  
  20. function UnitTestManager:RunTests()
  21.  
  22.     //no trouble using self now when hooked to a console event.
  23.  
  24.     for i,v in pairs(self.tests) do
  25.  
  26.     end
  27.  
  28. end
  29.  
  30. //global so it can be called in different test files without having to recreate this line:
  31. UnitTestManager = GetGUIManager():CreateGUIScriptSingle("UnitTestManager")
  32.  
  33. if not UnitTestManager_Hooked then //wrapped in if so that saving changes to this file won't cause additional hooks
  34.     UnitTestManager_Hooked = true
  35.  
  36.     local function Test()
  37.         UnitTestManager.RunTests(this) //this = self of the instance.
  38.     end
  39.  
  40.     Event.Hook("Console_test", Test)
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement