Banknorris |
01-16-18 06:52 PM |
Quote:
Originally Posted by Resike
(Post 326500)
Except you are not hooking a function call, but a call for it's memory pointer's reference.
You can try it yourself:
Lua Code:
hooksecurefunc("SetCVar", function(name, value) if name == "Sound_EnableMusic" then print(name, value) end end) local SetCVar = SetCVar SetCVar("Sound_EnableMusic", 1)
You can do this in the other way around, it won't change a thing:
Lua Code:
local SetCVar = SetCVar hooksecurefunc("SetCVar", function(name, value) if name == "Sound_EnableMusic" then print(name, value) end end) _G.SetCVar("Sound_EnableMusic", 1)
|
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.
|