User:Cogswobble/Addon Tutorial/Structure of an Addon

Before you create an addon, you need to understand the basic structure of addons, and how WoW finds and loads them. Below is description of this structure. More detail will be given when actually constructing an addon.

Basic Structure
All files for an addon are stored in a directory with the name of the addon. This directory can contain multiple levels of subdirectories containing more files. Most addons are composed of three basic file types: TOC, XML, and Lua. Other files may be included as well (e.g. custom graphic files).

TOC
Every addon has one (and only one) TOC file. The TOC is the Table of Contents for the addon. It contains some basic information about the addon, as well as a manifest of the XML and Lua files used by the addon. TOC files are named as AddonName.toc and must appear in the top level directory for the addon.

Example of a TOC file: MyScript.lua MyAddOn.xml MyFrame.xml MyButton.xml
 * 1) Interface: 30000
 * 2) Title : MyAddOn
 * 3) Notes: This AddOn does nothing but display a frame with a button
 * 4) Author: My Name
 * 5) eMail: Author@Domain.com
 * 6) URL: http://www.wowwiki.com/
 * 7) Version: 1.0
 * 8) Dependencies: Sea
 * 9) OptionalDeps: Chronos
 * 10) DefaultState: enabled
 * 11) SavedVariables: settingName, otherSettingName

For more information, see TOC format

Lua
Lua is a programing language which is used to instruct an addon how to behave. Most addons will have at least one Lua file. UNKNOWN: Can an addon with only XML files be used to modify the look of standard UI components/widgets?

Lua files end with the .lua extension and can appear anywhere within the directory or subdirectories of an addon.

Example of a Lua file: function MyAddon_OnLoad SlashCmdList["MyAddon"] = MyAddon_SlashCommand; SLASH_MYADDON1= "/myaddon"; this:RegisterEvent("VARIABLES_LOADED") end

For more information, see Lua.

XML
XML is a language for describing data. Different pieces of data can be "tagged" with labels (e.g. Cogswobble ). Blizzard uses XML to describe graphical elements of it's interface (some times refered to as widgets). XML files end with the .xml extension and can appear anywhere within the directory or subdirectories of an addon.

One of the elements the XML can contain is a reference to a Lua script for handling events from a widget.

Example of an XML file:               For more information, see XML user interface

Loading Addons
Addons are installed by copying their directory to \Interface\AddOns. When WoW is started, it checks this directory for addons. It reads their TOC files and uses this information to bring the addon into memory (assuming that the addon is configured as load on start up, which is the default). The information in the top part of the TOC is used to verify that the UI version is up to date and to communicate with the user (title and notes).