update HookScript function

This commit is contained in:
Pinya
2018-07-23 17:59:17 +03:00
parent 73c25f894c
commit 6579534c59
+7 -9
View File
@@ -82,21 +82,19 @@ QuestDifficultyColors = {
["header"] = {r = 0.70, g = 0.70, b = 0.70} ["header"] = {r = 0.70, g = 0.70, b = 0.70}
} }
function HookScript(frame, scriptType, handler) function HookScript(frame, scriptName, handler)
if not (type(frame) == "table" and frame.GetScript and type(scriptType) == "string" and type(handler) == "function") then if not (type(frame) == "table" and frame.GetScript and type(scriptName) == "string" and type(handler) == "function") then
error("Usage: HookScript(frame, \"type\", function)", 2) error("Usage: HookScript(frame, \"type\", function)", 2)
end end
local original_scipt = frame:GetScript(scriptType) local original_scipt = frame:GetScript(scriptName)
if original_scipt then if original_scipt then
frame:SetScript(scriptType, function(...) frame:SetScript(scriptName, function()
local original_return = {original_scipt(unpack(arg))} original_scipt(this)
handler(unpack(arg)) handler(this)
return unpack(original_return)
end) end)
else else
frame:SetScript(scriptType, handler) frame:SetScript(scriptName, handler)
end end
end end