12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

484 Part III ■ Advanced Addon Techniquesthings like frame attributes or previously stored in<strong>for</strong>mation, as well ascurrent API checks <strong>of</strong> approved in<strong>for</strong>mation, such as whether you have atarget, or other legitimate macro conditions.Notice that the SecureH<strong>and</strong>lerWrapScript call refers to BuffCycler twice.When you call SecureH<strong>and</strong>lerWrapScript, you have to give it two frames,which can be the same or different frames. The first one is the frame whosescript h<strong>and</strong>ler you will actually wrap. The second one (the third argument) isthe ‘‘owner’’ <strong>of</strong> the script; any private variable references (explained in moredetail a little later in the chapter) are associated with that frame. All scriptsowned by a frame have access to all private variables created by any scriptowned by that frame.To prevent exploits, only an explicitly protected frame (one inheriting fromatemplatewiththeprotected=“true“ tag attribute) can be designated as ascript owner. Moreover, snippets wrapping a frame script will not be run ifthe wrapped frame becomes unprotected, such as by having all its protectedchildren re-parented to other frames. Its original script will be run withoutmodification, <strong>and</strong> its wrappers will resume functioning if it becomes protectedagain.WARNING At the time <strong>of</strong> this writing, implicit protection is not sufficient toallow script wrappers to run on a frame; any script wrappers on a frame that is notexplicitly protected will be created successfully, but will be silently ignored. It ispossible that a future version <strong>of</strong> the secure h<strong>and</strong>lers will lift this restriction, butuntil such a change is made, you can make protected proxy frames with suitablescripts <strong>and</strong> have them manipulate references to the frames you want to control.It is also possible to unwrap a script, so that it returns to its originalbehavior. SecureH<strong>and</strong>lerUnwrapScript(wrappedFrame, scriptName) willsecurely restore the original h<strong>and</strong>ler, <strong>and</strong> return the prebody snippet, owningheader frame, <strong>and</strong> postbody snippet, allowing you to put the wrapper backon if needed.Using a Post-HookIf two strings are supplied to SecureH<strong>and</strong>lerWrapScript, the second one is apost-hook snippet called after the original h<strong>and</strong>ler completes. Most pre-hookscan include a message as an additional return value; if this message is non-nil,the post-hook is called <strong>and</strong> receives the message as an additional argument.Post-hooks are commonly used to per<strong>for</strong>m clean-up or change an addon’sstate in<strong>for</strong>mation after an action completes, setting it up <strong>for</strong> the next action.You can use this to make the menu frames created by BlessedMenus actmore like conventional popup menus, closing after a choice is made fromthem. Open up the BlessedMenus.xml file <strong>and</strong> find the first template,BlessedMenusSpellButtonTemplate. LocateitsOnLoad h<strong>and</strong>ler <strong>and</strong> add thefollowing statement at the end <strong>of</strong> the h<strong>and</strong>ler:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!