Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
No edit summary
 
(example, conformist format)
Line 1: Line 1:
 
{{wowapi}}__NOTOC__
 
{{wowapi}}__NOTOC__
Creates a secure 'post hook' for the named function. The hookfunc is invoked after the original function, and receives the same parameters. Return values from hookfunc are discarded. This is the only safe way to hook functions that execute protected functionality.
+
Creates a secure 'post hook' for the named function. Your hook will be called with the same arguments, but will not be able to affect the outcome of the original call.
  +
 
hooksecurefunc([table,] "functionName", hookfunc)
 
hooksecurefunc([table,] "functionName", hookfunc)
   
===Takes===
+
==Parameters==
  +
===Arguments===
:;table : table which functionName exists on
 
  +
:;table : Optional Table - if you're hooking a function on an object, reference the object name.
 
:;functionName : String - the name of the function being hooked.
 
:;hookfunc : Function - your hook function.
   
  +
==Example==
:;"functionName" : the name of the function being hooked
 
  +
local echoHook = function (...)
  +
local msg = , "";
  +
table.foreach({...}, function(k,v) msg = msg .. k .. "=[" .. tostring(v) .."] "; end);
  +
DEFAULT_CHAT_FRAME:AddMessage("[Echo] " .. msg);
  +
end;
  +
hooksecurefunc("CastSpellByName", echoHook); -- Hooks the global CastSpellByName
  +
hooksecurefunc(GameTooltip, "SetUnitBuff", echoHook); -- Hooks GameTooltip.SetUnitBuff
 
===Result===
  +
Hooks CastSpellByName and GameTooltip.SetUnitBuff without compromising their secure status. When those functions are called, prints their argument list into the default chat frame.
   
  +
==Notes==
:;hookfunc : the hook function
 
  +
This is the only safe way to hook functions that execute protected functionality.
===Returns===
 
: Nothing
 
   
  +
The hookfunc is invoked after the original function, and receives the same parameters; return values from hookfunc are discarded.
===Details===
 
  +
* After hooksecurefunc() is used on a function, setfenv() throws an error when attempted on that function
+
After hooksecurefunc() is used on a function, setfenv() throws an error when attempted on that function

Revision as of 11:28, 26 December 2006

Creates a secure 'post hook' for the named function. Your hook will be called with the same arguments, but will not be able to affect the outcome of the original call.

hooksecurefunc([table,] "functionName", hookfunc)

Parameters

Arguments

table
Optional Table - if you're hooking a function on an object, reference the object name.
functionName
String - the name of the function being hooked.
hookfunc
Function - your hook function.

Example

local echoHook = function (...) 
 local msg = , "";
 table.foreach({...}, function(k,v) msg = msg .. k .. "=[" .. tostring(v) .."] "; end);
 DEFAULT_CHAT_FRAME:AddMessage("[Echo] " .. msg);
end;
hooksecurefunc("CastSpellByName", echoHook); -- Hooks the global CastSpellByName
hooksecurefunc(GameTooltip, "SetUnitBuff", echoHook); -- Hooks GameTooltip.SetUnitBuff

Result

Hooks CastSpellByName and GameTooltip.SetUnitBuff without compromising their secure status. When those functions are called, prints their argument list into the default chat frame.

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.

After hooksecurefunc() is used on a function, setfenv() throws an error when attempted on that function