Thread Tools Display Modes
10-18-13, 07:07 AM   #1
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
[HELP] Hooking addon

Hello,

I would like to create a small addon that overrides another addon in certain conditions, like that:

Code:
-- targetted addon code
function originalFcn(param1, param2)
	print("original addon -"..param1.."-"..param2);
end
When this function is called in the targetted addon, i would like to this code in my addon:
Code:
-- my addon code
function myFcn(param1, param2)
	if (myAddon_isOn) then -- my addon settings
		-- hook
		print("myaddon..param1..param2);
		-- do not execute originalFcn() function!
	else
		-- don't do anything, let's the original code run
	end;
end
Is it possible to do such thing? If yes, could you tell me how?

Thanks in advance.
  Reply With Quote
10-18-13, 07:51 AM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
If the other addon has their function as a global like in your example yes it's quite possible.

You store a reference to the original function then replace it with your own.
A typical pre-hook scenario.

Addon1
Code:
function func1(...)
  -- do stuff
end
Addon2
Code:
local orig_func1 = func1
func1 = function myFunc(...)
  if --[[set of conditions]] then
    -- do stuff
  else
    orig_func1(...) -- or let Addon1 do its stuff
  end
end
Edit: Note that if you are the author of both addons or can request changes to either one there's much better ways of getting 2 addons to work together than overwriting each others functionality.
  Reply With Quote
10-19-13, 06:13 AM   #3
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
Hello Dridzt, and thank you very much!
Your code works fine
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » [HELP] Hooking addon


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off