WoWInterface - View Single Post - How can I hooksecurefunc with colon like this: "MainMenuBarMixin:OnShow"
View Single Post
08-21-18, 06:17 PM   #6
Nikita S. Doroshenko
A Cyclonian
Nikita S. Doroshenko's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2015
Posts: 44
Originally Posted by Gethe View Post
It depends on 1) when the mixin is created 2) when the function is hooked and 3) when the frame has the mixin applied.

In Ammako's case, ExpBarMixin is created and is applied to a template in the frame xml, before any addon gets loaded. The template however is not used for instantiating a frame until PLAYER_ENTERING_WOLRD fires, which is typically after most addons are loaded. As such, any hooks applied to the mixin before PLAYER_ENTERING_WOLRD fires will propagate the the new frame.

In Nikita's case, MainMenuBarMixin is created and immediately used in the creation of MainMenuBar. This means there is no allowance for any hooks to be made and applied via the mixin.
The thing that is confusing me, is hoocsecurefunc sometimes toggle lua errors like "funxtionX is not a function"
For example, I tried to hook some functions like function PlayerTalentFrame_UpdateSpecFrame(self, spec) from Blizzard_TalentUI.lua:

Lua Code:
  1. function PlayerTalentFrame_UpdateSpecFrame(self, spec)
  2.     local playerTalentSpec = GetSpecialization(nil, self.isPet, specs[selectedSpec].talentGroup);
  3.     local shownSpec = spec or playerTalentSpec or 1;
  4.     local numSpecs = GetNumSpecializations(nil, self.isPet);
  5.     local petNotActive = self.isPet and not IsPetActive();
  6.     local sex = self.isPet and UnitSex("pet") or UnitSex("player");
  7.     -- and so on... very large function
  8. end
So I used this code:
Lua Code:
  1. local function Test(self, spec)
  2.     print("test")
  3.     print(self)
  4.     print(spec)
  5. end
  6. hooksecurefunc('PlayerTalentFrame_UpdateSpecFrame', Test)
And got this: Error. hooksecurefunc(): PlayerTalentFrame_UpdateSpecFrame is not a function

At the same time, for example:
Lua Code:
  1. local function Test(self, spec)
  2.     print("test")
  3.     print(self)
  4.     print(spec)
  5. end
  6. hooksecurefunc('SpellBookFrame_UpdateSkillLineTabs', Test)
Works perfectly.

Can't understand why this happens, and will appreciate any advises how to hook functions with "funxtionX is not a function" error.
  Reply With Quote