WoW:Hooking functions: Difference between revisions

m
Line 48: Line 48:


Using [[Sea.util.hook]] will take care of parameter passing, priorities, chains and making sure you can clean yourself up later.
Using [[Sea.util.hook]] will take care of parameter passing, priorities, chains and making sure you can clean yourself up later.
== Optionally using Sea ==
If you don't want your AddOn to depend on [[Sea]], but you would like to take advantage of it when it's available, you can check for its presence:
  local MyAddOn_Old_FunctionToHook = function() end;
  if Sea then
    Sea.util.hook("FunctionToHook", "ReplacementFunction", "after");
  else
    MyAddOn_Old_FunctionToHook = FunctionToHook;
    FunctionToHook = ReplacementFunction;
  end
 
  function ReplacementFunction()
    MyAddOn_Old_FunctionToHook();
    ...
  end
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.


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