WoW:API hooksecurefunc: Difference between revisions
Jump to navigation
Jump to search
Added a note about hooking Blizzard frame event handler
(→Example: Use the 3.0 print.) |
(Added a note about hooking Blizzard frame event handler) |
||
Line 36: | Line 36: | ||
hooksecurefunc("ToggleBackpack", function() print(1) end) | hooksecurefunc("ToggleBackpack", function() print(1) end) | ||
hooksecurefunc("ToggleBackpack", function() print(2) end) | hooksecurefunc("ToggleBackpack", function() print(2) end) | ||
ToggleBackpack() | ToggleBackpack() | ||
> 1 | > 1 | ||
> 2 | > 2 | ||
Also note that using hooksecurefunc() may not always produce the expected result. Keep in mind that it actually replaces the original function with a new one (the function reference changes). | |||
For exemple, if you try to hook the global function "MacroFrame_OnHide" (after the macro frame has been displayed), your function will not be called when the macro frame is closed. | |||
It's simply because in Blizzard_MacroUI.xml the OnHide function call is registered like this: | |||
> <OnHide function="MacroFrame_OnHide"/> | |||
The function ID called when the frame is hidden is the former one, before you hoocked "MacroFrame_OnHide". | |||
The workaround is to hook a function called by "MacroFrame_OnHide": | |||
> hooksecurefunc(MacroPopupFrame, "Hide", MyFunction); |