AddonLoader

AddonLoader is a load manager, which can be used by addons to load them conditionally. For example an addon that only manages a Hunter's pets does not ever need to be loaded on a non-Hunter. AddonLoader allows the developer to specify certain load conditions for their addons, allowing them to be intelligently loaded on demand.

Download
AddonLoader can be downloaded at the following locations:


 * Curse.com
 * WowInterface.com

Usage (as a player)
Simply having AddonLoader present should cover your needs. There are some options that can be accessed through /addonloader for overriding an addon's load condition.


 * Never disable AddonLoader in the addon list - it will make all AddonLoader-aware addons stop loading. If you no longer want AddonLoader, you need to delete it.

Usage (as a developer)
AddonLoader allows you to specify certain conditions under which your addon will be loaded. It also enables you to run blocks of code without ever having your addon loaded, all by parsing the metadata in your table of contents file. Conditions are completely self-contained and do not interact with one another. Currently there is no way to (for example) specify by using simple metadata that your addon should only load for a certain class that is also over a certain level. You could accomplish this using an execute block instead.

Enabling AddonLoader

 * 1) LoadManagers: AddonLoader

This line in your TOC file tags your addon as LoadOnDemand, and assigns responsibility for loading it to AddonLoader. Warning- if AddonLoader is disabled in the addons panel, your addon will not load at all. If you don't wish to use AddonLoader, you must delete its folder from the Addons folder.

Special Fields

 * 1) X-LoadOn-Events: UNIT_SPELLCAST_START, UNIT_MANA
 * 2) X-LoadOn-UNIT_SPELLCAST_START: if arg1 == 'player' then AddonLoader:LoadAddOn('MyAddOn') end
 * 3) X-LoadOn-UNIT_MANA: if arg1 == 'player' then AddonLoader:LoadAddOn('MyAddOn') end

Specify events to register for. You must specify event reaction code for each event.


 * 1) X-LoadOn-Hooks: GameTooltip_SetDefaultAnchor, ChatFrame_OnEvent

Specify functions that are to be securely hooked. Other than that, works like Events above.


 * 1) X-LoadOn-Execute: ChatFrame1:AddMessage('MyAddOn is present, but not yet loaded')

This code will execute on login regardless of if the addon is loaded or not. Use this if you need to specify complicated loading circumstances like function hooks. Note that toc fields are limited to about 1000 characters, if you must go over that amount, use X-LoadOn-Execute2 etc. Multiples get concatenated together and executed as one.


 * 1) X-LoadOn-Slash: /myaddon, /myadd

This specifies a slash command to register when your addon is not loaded. When the command is used by the player, your addon will be loaded, then the typed command will be issued again, so that options can be accessed if your addon's load condition hasn't yet fired.

AddonLoader will register

SLASH_MYADDON1 SlashCmdList["MYADDON"] hash_SlashCmdList["/myaddon"] SLASH_MYADD1 SlashCmdList["MYADD"] hash_SlashCmdList["/myadd"]

When your addon loads you should make sure to nil these out before you load your slash commands, otherwise you can run into problems with your slash commands not being used.


 * 1) X-LoadOn-LDB-Launcher: Interface\AddOns\myAddon\icon
 * 2) X-LoadOn-LDB-Launcher: Interface\AddOns\myAddon\icon myAddonLauncher

This works similar to the slash loader, except with LDB launchers. AddonLoader will create an LDB launcher for your addon and set its OnClick action to load your addon, then call the new OnClick handler your addon creates. This also means your addon must handle the LDB dataobj carefully, to ensure it is declared correctly for users with and without AddonLoader installed.

local ldb = LibStub:GetLibrary("LibDataBroker-1.1") local dataobj = ldb:GetDataObjectByName("myAddonLauncher") or ldb:NewDataObject("myAddonLauncher", {type = "launcher", icon = "Interface\\AddOns\\myAddon\\icon"}) dataobj.OnClick = function(self, button) dosomethingonclick(button) end

The second arg is optional, if not present your addon's name will be used for the dataobject name. Also note that texture paths in the TOC use "\" while paths declared in lua must use an escaped "\\"


 * 1) X-LoadOn-InterfaceOptions: My Addon

AddonLoader will add a category to the interface options -> Addons tab. Upon clicking the category your addon will be loaded and the category will be refreshed. The addon loading is responsible for adding a category with the same name registered in the X-LoadOn-InterfaceOptions field.

-- In case the addon is loaded from another condition, always call the remove interface options if AddonLoader and AddonLoader.RemoveInterfaceOptions then AddonLoader:RemoveInterfaceOptions("My Addon") end -- now create our own contents local frame = CreateFrame("Frame", nil, UIParent) frame:Hide frame.name = "My Addon" -- fill the frame with options InterfaceOptions_AddCategory(frame)

Load Conditions

 * 1) X-LoadOn- : 