hooksecurefunc works on funcA, but not on funcB - WoWInterface
Thread Tools Display Modes
12-04-17, 12:19 AM   #1
A Murloc Raider
Join Date: Aug 2012
Posts: 8
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?
  Reply With Quote
12-04-17, 12:52 AM   #2
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
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.

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

Last edited by Ammako : 12-04-17 at 12:54 AM.
  Reply With Quote
12-04-17, 09:32 AM   #3
I did that?
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,307
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.
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
12-04-17, 11:00 AM   #4
A Chromatic Dragonspawn
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
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.
"In this world nothing can be said to be certain, except that fractional reserve banking is a Ponzi scheme and that you won't believe it." - Mandrill

Last edited by Banknorris : 12-04-17 at 01:55 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » hooksecurefunc works on funcA, but not on funcB

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off