WoW:Hooking functions: Difference between revisions

Added other hooking functions (other than Sea)
(→‎How to Hook a Function: Added a note that the level showing no longer works and is just an example)
(Added other hooking functions (other than Sea))
Line 70: Line 70:


This allows you to list Sea as an OptionalDep in your [[The_TOC_Format|TOC]].  This can help prevent future conflicts with other AddOns that replace the old function entirely, as long as the user installs Sea.
This allows you to list Sea as an OptionalDep in your [[The_TOC_Format|TOC]].  This can help prevent future conflicts with other AddOns that replace the old function entirely, as long as the user installs Sea.
== Other Hooking libraries ==
===[[Stubby]]===
With [[Stubby]] you can hook functions with [[Stubby.HookFunction]]
  Stubby.RegisterFunctionHook("FunctionToHook", position, replacementFunction [, hook1, hook2, .., hookN])
*The FunctionToHook is a string that names the function you want to hook into. eg: "[[API GameTooltip SetOwner|GameTooltip.SetOwner]]"
*The position is a negative or positive number that defines the actual calling order of the addon. The smaller or more negative the number, the earlier in the call sequence your hookFunction will be called, the larger the number, the later your hook will be called. The actual original (hooked) function is called at position 0, so if your addon is hooked at a negative position, your return values table (see below) will contain the return values of the previous function in Stubby's call chain.
*You pass (by reference) your function that you wish called as replacementFunction. This function will be called with the following parameters: hookFunction(hookParams, returnValue, hook1, hook2 .. hookN)
**hookParams is a table containing the additional parameters passed to the RegisterFunctionHook function (the "hook1, hook2, .., hookN" params)
**returnValue is an array of the returned values of the function called before you in [[Stubby]]'s call chain or nil if none.
**hook1..hookN are the original parameters of the hooked function in the original order.
*You can optionally return the following strings to Stubby for special handling cases:
**"abort" Will abort the call chain (will not call any other functions scheduled after your own).
**"killorig" Will not call the original function, but will continue the call chain.
**"setparams" Will replace the function's call paramenters with the ones you specify in a list on your function's second return value.
**"setreturn" will change the return values for the next function in [[Stubby]]'s call chain with your with the ones you specify in a list on your function's second return value.
===[[Ace]]===
===[[Ace2]]===


== Where to Call the Old Function ==
== Where to Call the Old Function ==
Anonymous user