ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Adding multiple handlers (https://www.esoui.com/forums/showthread.php?t=1652)

Iyanga 05/27/14 03:59 PM

Adding multiple handlers
 
If a control has a handler already set, for example for "OnMouseEnter", you can add your own handler like this:

local oldHandler = control:GetHandler(event)
control:SetHandler(event, function(...) oldHandler(...) myhandler(...) end)

Unfortunately, this doesn't work when the oldHandler function uses private functions. As the function is now called from the addon environment, this leads to an exception for trying to call a private function.

Any ideas how to circumvent this problem?

I tried assigning the old handler to a global variable and use "CallSecureProtected("myglobalvariablename", ...), but this didn't work either, it's not called at all.

ingeniousclown 05/27/14 04:13 PM

You could try using ZO_PreHookHandler() that I THINK exists because I THINK I remember hearing someone talking about it in IRC or some other thread...

But I believe that would be a 100% safe way to do what you're wanting UNLESS you absolutely need a post-hook instead...

In a case like that, I'd still prehook and then in the called function, do a zo_callLater(myFunction(myArgs), 25) to make the function fire almost instantly after the handle function. Very hacky, but it works.

Vuelhering 05/27/14 04:34 PM

haha, yeah... that's just aching for a race condition on a crappy computer. :)

ingeniousclown 05/27/14 07:13 PM

Quote:

Originally Posted by Vuelhering (Post 8639)
haha, yeah... that's just aching for a race condition on a crappy computer. :)

You're not wrong, but if a mouse-over event handler takes more than 25ms to terminate, there's a whole host of other problems.

Iyanga 05/28/14 01:08 PM

Quote:

Originally Posted by ingeniousclown (Post 8636)
You could try using ZO_PreHookHandler() that I THINK exists because I THINK I remember hearing someone talking about it in IRC or some other thread...

Yeah, that's what I thought, too, couldn't find the thread yesterday though. Guess was blind, I wrote in that thread, too. :o

ZO_PreHookHandler() works like a charm for my case, no problem with internals overriding my settings afterwards.


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

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