WoWInterface (
-   Lua/XML Help (
-   -   hooksecurefunc works on funcA, but not on funcB (

robertito54321 12-04-17 12:19 AM

hooksecurefunc works on funcA, but not on funcB
So I'm attempting to add some code to a global function for VuhDo.
Unfortunately I cant seem to figure out why I can hook a func to 'function A', but not to 'function B'

[WORKS] Function A (VuhDo -> VuhDoDebuffs.lua):

function VUHDO_determineDebuff(aUnit)
  --Some code
local VUHDO_determineDebuff = VUHDO_determineDebuff;

[DOESNT WORK] Function B (VuhDo -> VuhDoBarCustomizerHealth.lua):

function VUHDO_customizeText(aButton, aMode, anIsTarget)
  --Some code
local VUHDO_customizeText = VUHDO_customizeText;

My testhook: (hook for function a looks the same)

  local f = CreateFrame("Frame")
  f:SetScript("OnEvent", function(self,event,...)
    if IsAddOnLoaded("VuhDo") then
      hooksecurefunc("VUHDO_customizeText", function() print("This is a test") end)

The hook for function B only seems to work when I comment out the following line:
Note: on function A I dont need to comment out anything. It always works :/

--local VUHDO_customizeText = VUHDO_customizeText;
Can someone help me out on how to debug this issue?

_G["VUHDO_customizeText"] --this exists, can I safely assume its a global function and it should work?

Ammako 12-04-17 12:52 AM

Not actually a solution to your issue, but PLAYER_ENTERING_WORLD fires at more than just player login, so you may want to make sure your code won't be creating multiple hooks as a result. Wasteful at best, harmful at worst if the hooks end up interfering with each other or causing performance issues. :p

ADDON_LOADED may be a better choice, but keep in mind that would require your addon to load before VuhDo does.

Fizzlemizz 12-04-17 09:32 AM

Just hook the global function rather than trying to localise it first. Other than that, without the actual code it's a bit hard to tell what might be going on.

PLAYER_LOGIN fires after all the ADDON_LOADEDs and before PLAYER_ENTERING_WORLD and only fires once.

Banknorris 12-04-17 11:00 AM

Without checking the files I would guess that function A hook is working because Vuhdo is actually calling VUHDO_determineDebuff from outside file VuhDoDebuffs.lua and in those files the local version does not exist.

On the other hand VUHDO_customizeText is being called from within the files VuhDoBarCustomizerHealth.lua where local version is called instead of the global version. When you hook a function you in fact make another function but the local version is pointing to a pre hook version.

You can confirm with this macro


/run function a()print("function")end local f=a hooksecurefunc("a",function()print("hook")end) local g=a f()g()
f() call does NOT call the hook function because it is poiting to a version of the global function a that has no hooks

whereas g() call does call the hook function because it is a local reference to the hooked global function a.

All times are GMT -6. The time now is 08:23 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI