→Hooking functions with ":" in there name: avoid tags for formatting
m (→Hooking functions with ":" in there name: Added a comment to clear up example) |
(→Hooking functions with ":" in there name: avoid tags for formatting) |
||
| Line 119: | Line 119: | ||
You can hook a function like "AddonName:Function()" by replaceing the ":" with a ".". | You can hook a function like "AddonName:Function()" by replaceing the ":" with a ".". | ||
For example if the below code is from someone's addon: | For example if the below code is from someone's addon: | ||
function AnAddon.Module:FuncName(per1,per2) | |||
-- Things happen here... | |||
end; | |||
function AnAddon.Module:FuncName(per1,per2) | |||
end; | |||
You can use the following to pre-hook it: | You can use the following to pre-hook it: | ||
local original_AnAddon_Module_FuncName = AnAddon.Module.FuncName; -- Store the original function encase you want to use it. | |||
function AnAddon.Module:FuncName(per1,per2) -- This is the new function to overwrite the original one | |||
if (per1 > 10) then | |||
local original_AnAddon_Module_FuncName = AnAddon.Module.FuncName; -- Store the original function encase you want to use it. | ChatFrame1:AddMessage(tostring(per1)); | ||
else | |||
function AnAddon.Module:FuncName(per1,per2) -- This is the new function to overwrite the original one | original_AnAddon_Module_FuncName(self,...); -- Calls original function like nothing happened | ||
end; | |||
end; | |||
end; | |||
Assuming per1 is a number greater than 10 then per2 will be printed and if per1 isn't then the original function will run. | Assuming per1 is a number greater than 10 then per2 will be printed and if per1 isn't then the original function will run. | ||