Thread Tools Display Modes
04/17/23, 01:03 AM   #1
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Question 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?

Last edited by sinnereso : 04/17/23 at 01:31 AM.
  Reply With Quote
04/17/23, 02:24 AM   #2
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
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

Last edited by votan : 04/17/23 at 02:48 AM.
  Reply With Quote
04/17/23, 05:23 AM   #3
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
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
  Reply With Quote
04/17/23, 06:53 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,966
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
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » possible to disable/remove a hook?


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