Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:API hooksecurefunc
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Notes== This is the only safe way to hook functions that execute protected functionality. The ''hookfunc'' is invoked after the original function, and receives the same parameters; return values from hookfunc are discarded. If another addon, or the same addon, replaces ''functionName'' after you use this function to hook it, ''hookfunc'' will no longer fire. ... except of course if your new function calls the old original! hooksecurefunc("ToggleBackpack", function(...) print("ToggleBackpack called.") end) ToggleBackpack = function(...) -- Do something different end ToggleBackpack() -- "ToggleBackpack called." never prints. After hooksecurefunc() is used on a function, setfenv() throws an error when attempted on that function You cannot "unhook" a function that is hooked with this function except by a UI reload. Calling hooksecurefunc() multiple times only ''adds'' more hooks to be called. hooksecurefunc("ToggleBackpack", function() print(1) end) hooksecurefunc("ToggleBackpack", function() print(2) end) ToggleBackpack() > 1 > 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 example, 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 hooked "MacroFrame_OnHide". The workaround is to hook a function called by "MacroFrame_OnHide": hooksecurefunc(MacroPopupFrame, "Hide", MyFunction) However, when you want to hook a frame's script handler, it's better to use [[API_Frame_HookScript|Frame:HookScript]] like this: MacroPopupFrame:HookScript("OnHide", MyFunction) -- the client will call MacroFrame_OnHide(MacroPopupFrame) first followed by MyFunction(MacroPopupFrame)
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)