Advertisement
FocusedWolf

Event.Hook Workaround v2

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