ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   possible to disable/remove a hook? (https://www.esoui.com/forums/showthread.php?t=10516)

sinnereso 04/17/23 01:03 AM

possible to disable/remove a hook?
 
Ive been looking all night and cant find any mention of how to remove a hook.

Im looking to unregister events(which is no problem to do) and disable a posthook when a feature is disabled.

its being enabled like this onload and when toggled on:

Code:

ZO_PostHook("ZO_Armory_Keyboard_CollapsedEntry_OnMouseUp", MyAddon.MyFunction)
is there a way to shut that off when its not needed?

votan 04/17/23 02:24 AM

The answer is: In theory yes, practical no.
Of course you could store the original reference and restore it at some point.
But! If someone else is also hooking that, you would disable all hooks done after yours. Bad concept.
So, no, you should not do this!

What you could do is: Use a boolean for skipping any action.

/edit:
Or keep the hook, but the hook itself is just calling a function reference.
Lua Code:
  1. local current = MyAddon.MyFunction
  2. local function NoOp() end
  3. ZO_PostHook("ZO_Armory_Keyboard_CollapsedEntry_OnMouseUp", function(...) return current(...) end)
Now, *current* can be assigned with NoOp and at some point again with MyAddon.MyFunction.
That is a so-called "tail call". See https://www.lua.org/pil/6.3.html

sinnereso 04/17/23 05:23 AM

Ya thats sort of what ive done... the beginning of the function checks is feature disabled and then return end if so.. else do the hook stuff :)..

Thank you I just wanted to be sure cuz I couldnt even find any mention of it nevermind how it would be done. SOO mysterious the answer was =p

Baertram 04/17/23 06:53 AM

If you gus find out such stuff is missing, maybe add it to the Wiki please!

Added here:
https://wiki.esoui.com/How_to_run_yo...#Disable_hooks


All times are GMT -6. The time now is 11:25 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI