View Single Post
08-01-19, 04:02 AM   #8
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 321
All right, thanks for the clarification! Now I understand the difference between SetScript and HookScript. :-D

However, if other Addons use the same method as you suggested, I have again no controll over which one is loaded first, right?

E.g. the author of LibExtraTip (used by TheUndermineJournal) does it like this (LibExtraTip.lua, L545):

Lua Code:
  1. -- Called to install/modify a pre-hook on the given tooltip's event
  2. -- Currently we do not need any posthooks on scripts
  3. local function hookscript(tip, script, prehook)
  4.     if not lib.hookStore[tip] then lib.hookStore[tip] = {} end
  5.     local control
  6.     -- check for existing hook
  7.     control = lib.hookStore[tip][script]
  8.     if control then
  9.         control[1] = prehook or control[1]
  10.         return
  11.     end
  12.     -- prepare upvalues
  13.     local orig = tip:GetScript(script)
  14.     control = {prehook}
  15.     lib.hookStore[tip][script] = control
  16.     -- install hook stub
  17.     local stub = function(...)
  18.         local h
  19.         -- prehook
  20.         h = control[1]
  21.         if h then h(...) end
  22.         -- original hook
  23.         if orig then orig(...) end
  24.     end
  25.     tip:SetScript(script, stub)
  26. end

With your code, my lines always get appended after those of TheUndermineJournal.
  Reply With Quote