Shoutbox

[Beta-ish Utility Release] Hook System - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Beta-ish Utility Release] Hook System (/showthread.php?tid=64162)

[Beta-ish Utility Release] Hook System by Eljay on 07-28-2006 at 05:23 PM

Just a small utility thing ive been thinking of making and finally got so bored i actually made it. (dempsey now owes me 2p cos he bet i wouldnt make it :cheesy:)

Basically its a hook system (hence the extremely imaginative name). You create a function, then call Hook.add like so:

Hook.add(<event name here>, <function here (not in quotes!) >);

e.g.

code:
function blah(status){ Debug.Trace(status); }
Hook.add('OnEvent_MyStatusChange', blah);

now blah() is called with the first parameter of OnEvent_MyStatusChange as its first parameter (i.e. x = NewStatus). So the new status (number) is traced to the debug console.  Neat huh?

You can also remove functions from their hooks using the very easy to remember Hook.remove (which takes the exact same parameters as Hook.add)

Finally, if you so desire, you can add your own event hooks by calling Hook.newhook('nameofyourhook') and then calling Hook.call('nameofyourhook', {parameter object}) whenever you want the hooked functions to be triggered.


See attachment for usage example and the utility itself (_hooksystem.js)
RE: [Beta-ish Utility Release] Hook System by Chestah on 07-29-2006 at 03:39 AM

looks cool! i'll have a look at it tonight! thanks eljay ;)


RE: [Beta-ish Utility Release] Hook System by segosa on 07-29-2006 at 06:54 AM

It's good, it works... I just can't see how it's useful? No, really, I'm trying to think of a single use for it and I can't think of any :p. I've never really needed to rename the existing functions.


RE: RE: [Beta-ish Utility Release] Hook System by alexp2_ad on 07-29-2006 at 09:06 AM

quote:
Originally posted by segosa
It's good, it works... I just can't see how it's useful? No, really, I'm trying to think of a single use for it and I can't think of any :p. I've never really needed to rename the existing functions.

I can see that it makes it easy to add and remove functionality on the fly.  Eg.  instead of having a variable used in an if that sets whether a certain option is run, you can just add the functionality with the hook when the option is changed.

Might make bug finding a little difficult though, since you might not be sure what order the functions are being called.  *-)
RE: [Beta-ish Utility Release] Hook System by Eljay on 07-29-2006 at 09:11 AM

quote:
Originally posted by segosa
It's good, it works... I just can't see how it's useful? No, really, I'm trying to think of a single use for it and I can't think of any :p. I've never really needed to rename the existing functions.

well blah, give me an idea for something useful and ill (try to :P) make it cos im bored out of my skull.
RE: [Beta-ish Utility Release] Hook System by Keikonium on 07-29-2006 at 10:59 AM

Speaking of hooking messenger...

Would it be possible thru a script and external .dll's to create something that would allow us to add icons to the dashboard in the main window? I'm thinking a browse button for .exe files that would grab the program icon, and display it in the dashboard. Then upon clicking the icon would launch the program. Or better yet defining a picture on the harddrive to display as the icon.

I know Plus! and Stuffplug and some tweaks with mess patch can add dashboard icons, so I don't *think* it is impossible. I've read that a script can do most of what .exe's can do, and since Plus! can add a dashboard icon, it shouldn't be out of the league of a script should it? I'm just talking off the top of my head here, but its something I have always wanted :D.


RE: RE: RE: [Beta-ish Utility Release] Hook System by segosa on 07-29-2006 at 12:39 PM

quote:
Originally posted by alexp2_ad
quote:
Originally posted by segosa
It's good, it works... I just can't see how it's useful? No, really, I'm trying to think of a single use for it and I can't think of any :p. I've never really needed to rename the existing functions.

I can see that it makes it easy to add and remove functionality on the fly.  Eg.  instead of having a variable used in an if that sets whether a certain option is run, you can just add the functionality with the hook when the option is changed.

Might make bug finding a little difficult though, since you might not be sure what order the functions are being called.  *-)


Good point, didn't think of that.