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.

CHAPTER19Altering Existing Behaviorwith Function HookingMost addons are designed as self-contained additions to the default userinterface. These addons make use <strong>of</strong> the provided API <strong>and</strong> the frames <strong>and</strong>functionality in the default user interface. Sometimes, however, it makes senseto alter the existing behavior <strong>of</strong> the UI. One way that can be accomplishedis known as function hooking. This chapter introduces the concept <strong>of</strong> functionhooking, including specific rules to follow <strong>and</strong> pitfalls to avoid.What Is Function Hooking?‘‘Hooking a function’’ is mostly just a fancy way <strong>of</strong> saying ‘‘changing thebehavior <strong>of</strong> a function.’’ Like any other Lua variable, you can overwrite afunction value with a new one <strong>of</strong> your creation. Then, any time code tries tocall the function, it will use yours instead. More specifically, though, functionhooking means that the original function still runs, at least when a functionhook behaves properly.Function hooks are used to alter the behavior <strong>of</strong> an existing function in one<strong>of</strong> the following ways:Altering the arguments to or the return values from the original function.Preventing the original function from running.Taking extra action each time the function is called.359

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

Saved successfully!

Ooh no, something went wrong!