Quantcast
WoWInterface - View Single Post - About add-ons optimization
View Single Post
01-17-18, 02:42 PM   #67
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,289
Originally Posted by Banknorris View Post
What would happen if in the last line of the second code you have used SetCVar("Sound_EnableMusic", 1) instead of _G.SetCVar("Sound_EnableMusic", 1)? Would it still print anything? If not then that is exactly the point, calling a local reference to a global function when the attribution of the local is made BEFORE you hook the global function will result in the hook (by that I mean the function with print(name,value) not being called. But of course the hooked function (SetCVar) will run normally.

That was exactly what Semlar said. If in my addon I don't call _G.SetCVar but a local version of it and your addon (which wants to track SetCVar calls by hooksecurefunc'ing it) loads after mine, then you will not be able to see my SetCVar calls. Hence the advice to use _G.SetCVar (implicitally, by just not defining a local version of it) that is just a little bit slower but don't interfere with hooks.
Still works. Actually it only works with the _G.

So this indeed does not seems to work, i might have been wrong about this, since i doubt it would be the post-patch changes:

Lua Code:
  1. local SetCVar = SetCVar
  2.  
  3. hooksecurefunc("SetCVar", function(name, value)
  4.     if name == "Sound_EnableMusic" then
  5.         print(name, value)
  6.     end
  7. end)
  8.  
  9. SetCVar("Sound_EnableMusic", 1)

Last edited by Resike : 01-17-18 at 02:57 PM.
  Reply With Quote