From 597f19dd55d1e9ed01d06a5195fd02970416cb65 Mon Sep 17 00:00:00 2001 From: shagu Date: Sun, 14 Apr 2019 15:14:47 +0200 Subject: [PATCH] api: add HookScript back to the core api --- api/api.lua | 13 +++++++++++++ compat/vanilla.lua | 8 -------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/api/api.lua b/api/api.lua index b255e0c3..cbb8b204 100644 --- a/api/api.lua +++ b/api/api.lua @@ -351,6 +351,19 @@ do -- create a scope so we don't have to worry about upvalue collisions end end +-- [ HookScript ] +-- Securely post-hooks a script handler. +-- 'f' [frame] the frame which needs a hook +-- 'script' [string] the handler to hook +-- 'func' [function] the function that should be added +function HookScript(f, script, func) + local prev = f:GetScript(script) + f:SetScript(script, function() + if prev then prev() end + func() + end) +end + -- [ HookAddonOrVariable ] -- Sets a function to be called automatically once an addon gets loaded -- 'addon' [string] addon or variable name diff --git a/compat/vanilla.lua b/compat/vanilla.lua index 075a35eb..db9e65a6 100644 --- a/compat/vanilla.lua +++ b/compat/vanilla.lua @@ -48,11 +48,3 @@ function hooksecurefunc(name, func, append) _G[name] = pfUI.hooks[tostring(func)]["function"] end - -function HookScript(f, script, func) - local prev = f:GetScript(script) - f:SetScript(script, function() - if prev then prev() end - func() - end) -end