Addon Manager simplifies registration of addons, and also adds to unifying the addon structure. All registered addon will follow this structure:
Code:
object.Addon.Name -- Unique addon name
object.Addon.Version -- A version identifier (typically a string in the format {major}.{minor}.{revision})
object.Addon.Author -- The name of the addon author
object.Addon.Name -- A description of the addon
In addition to the structure above all addons will have two events (functions) ready to be used:
Code:
object:OnLoad -- Gets fired as soon as this addon is being loaded (typically where you prepare your addon)
object:OnReady -- Gets fired as soon as the player is ready (now we know the player is ready to recieve messages and such)
If you have defined the OnLoad function (this is optional) a message will be added to the chat window when the OnLoad function has completed execution. This message will be as follows:
{addonName} {version} loaded!
To disable the automatic loaded message you can set SupressLoadMessage to true before you register the OnLoad function:
Code:
object.SupressLoadMessage = true
Installation:
--------------
Copy ADDONS.lua to a subfolder of your add-on (/lib/ for example)
Add a new line in your manifest file (.txt):
lib/ADDONS.lua
Now Addon Manager is ready
Usage:
--------
There is two ways to register an new addon:
A) Create a new Addon class (this will create a new table):
Code:
local fooAddon = ADDONS:Create("FooAddon", "0.1.0", "author", "description")
B) Register an existing table as a Addon class:
Code:
local fooAddon
ADDONS:Register(fooAddon, "FooAddon", "0.1.0", "author", "description")
Note: Author and Description are both optional parameters
Should you need to check if a addon is registered, or you need to get your addon from another LUA filer, simply call "Get":
Code:
local fooAddon = ADDONS:Get("FooAddon")
Example:
-----------
Code:
local fooAddon = ADDONS:Create("FooAddon", "0.1.0", "author", "description")
function fooAddon:OnLoad()
d("Addon " .. self.Addon.Name .. " is being loaded")
end
function fooAddon:OnReady()
d("And now we are ready!")
end
API Documentation:
------------------------
Warning: Spoiler
--- Creates a new addon class and a empty table
-- @param addonName The unique name of the addon
-- @param version A version identifier (typically a string in the format {major}.{minor}.{revision})
-- @param author The name of the addon author
-- @param description A description of the addon
-- @return A new Addon class with registered OnLoad and OnReady events Create(addonName, version , author, description)
--- Registers an existing table as a addon class
-- @param existingTable A table to be extended as a Addon class
-- @param addonName The unique name of the addon
-- @param version A version identifier (typically a string in the format {major}.{minor}.{revision})
-- @param author The name of the addon author
-- @param description A description of the addon
-- @return A new Addon class based on the existing table (or a new table if existingTable was nil) with registered OnLoad and OnReady events Register(existingTable, addonName, version, author, description)
--- Gets a registered addon, either from the internal reference table or from the global table.
--- Note: the addon doesn't need to be explicitly registered using the Addon Manager, any global table matching the name would be returned
-- @param addonName The unique name of the addon
-- @param silent Optional parameter indicating if an error message should be displayed in case no addon was found
-- @return A addon table (or nil if not found) Get(addonName, silent)
object.Addon.Name -- Unique addon name
object.Addon.Version -- A version identifier (typically a string in the format {major}.{minor}.{revision})
object.Addon.Author -- The name of the addon author
object.Addon.Name -- A description of the addon
The second `.Name` should maybe be something like `.Description`?