Module lib
Main methods directly available in your addon
Usage:
-- Create a new addon this way: local me,ns=... -- Wow engine passes you your addon name and a private table to use addon=LibStub("LibInit"):newAddon(ns,me) -- Since now, all LibInit methods are available on self
Info:
- Release: 64
- Author: Alar of Runetotem
Fields
mixins | Mixins list |
options | Runtime storage for information on LibInit managed addons. |
pool | Recycling system pool. |
toggles | Runtime storage for variables. |
Table Recycling System
DelTable (tbl[, recursive=true]) | Returns a table to the recycle pool Table will be wiped Only manages tables allocated via NewTable Other tables are left intact -- Preferred usage is assigning to a local via wrap function |
NewTable ([tbl=nil]) | Get a new table from the recycle pool Preferred usage is assigning to a local via wrap function |
Addon management
NewAddon ([target], name[, options[, full[, ...]]]) | Create a new AceAddon-3.0 addon. |
Compatibility
GetCurrencyInfo (id) | Compatibility: Emulates renamed and modified GetCurrencyInfo |
GetMissionInfo (id) | Compatibility: Emulates removed C_Garrison.GetMissionInfo |
Wrap (name) | Returns a closure to call a method as simple local function |
Generic
Colorize (stringa, colore) | Colors a string. |
GetBagSlotCount () | Returns number of free bag slots and total bagt slots. |
GetChatFrame ([chat=DEFAULT_CHAT_FRAME]) | Return a named chatframe. |
GetItemID (itemlink) | Parses an itemlink and returns itemId without calling API again |
GetTotalBagSlots () | Return the total numner of bag slots |
Health (unit) | Returns unit's health as a normalized percent value |
Is (class, target) | Check if the unit in target hast the requested class |
NumericVersion () | Returns a numeric representation of version. |
OnLeaveCombat (action[, ...]) | Executes an action as soon as combat restrictions lift. |
Parse (msg, n) | Parses a command from chat or from an table options handjer command Internally calls AceConsole-3.0:GetArgs |
ScanBags ([index=0[, value=0[, startbag=0[, startslot=1]]]]) | Scans Bags for an item based on different criteria
All parameters are optional. |
Configuration panel
AddToggle (flag, defaultvalue, name[, description=name[, icon]]) | Create a boolean configuration var |
Trigger (flag) | Simulates a configuration variable change. |
Hooks
Empty (obj) | Implements PHP empty function. |
GetColorTable () | Returns a crayon like object |
GetFactory () | Returns a factory for lightweight widgets |
GetKpairs () | Returns kpairs implementation Deprecated in favour of Wrap("Kpairs") |
LoadHelp () | Called to fill the help system |
OnDisabled () | Called from the OnDisable ACE event |
OnEmbedDisable () | Called when the wmbedding addon is disabled |
OnEmbedEnable (first) | Called When the embedding addon is enabled |
OnEnabled ([first]) | Called from the OnEnable ACE event |
OnInitialized () | Called after VARIABLES_LOADED event, by OnInitialize Ace Hook |
Popup (msg[, timeout=60[, OnAccept[, OnCancel[, data[, StopCasting]]]]]) | Show a popup Display a popup message with Accept and optionally Cancel button |
SetDbDefaults (tbl) | Called with the db default table as argument |
SetOptionsTable (tbl) | Called with the current option table |
Coroutines
NewDelayableTimer (callback) | Delayable timers Create a timer that can be delayed. |
coroutineExecute (interval, action[, combatSafe[, more]]) | Generates and executes a coroutine with configurable interval and combat status If called for already running coroutine changes the interval and the combat status |
coroutineOnEnd (signature, action[, ...]) | Executes an action as soon as a coroutine exit Action can be executed immediately if coroutine is already dead |
Automatic events
StartAutomaticEvents () | Starts all automatic events. |
StopAutomaticEvents ([ignore]) | Stops all automatic events. |
Fields
- mixins
- Mixins list
- options
- Runtime storage for information on LibInit managed addons.
- pool
- Recycling system pool.
- toggles
- Runtime storage for variables.
Table Recycling System
A set of functions to allow for table reusing
Usage:
-- You better upvalue these functions local addon=LibStub("LibInit"):NewAddon("myaddon") local new=addon:Wrap("NewTable") local new=addon:Wrap("DelTable")
- DelTable (tbl[, recursive=true])
-
Returns a table to the recycle pool
Table will be wiped
Only manages tables allocated via NewTable
Other tables are left intact
-- Preferred usage is assigning to a local via wrap function
Parameters:
- tbl table table to be recycled
- recursive boolean If true, embedded tables added via new table will be wiped and recycled (default true)
- NewTable ([tbl=nil])
-
Get a new table from the recycle pool
Preferred usage is assigning to a local via wrap function
Parameters:
- tbl table Optional table which will be added to the pool after use. Must NOT have a metatable (default nil)
Returns:
-
table
A new table or a recycled one. Table is wiped
Usage:
-- Assuming you upvalued it as new local t=new() -- do something del(t) t=new() t.check=new() del(t,true) -- will recycle both t and t.check
Addon management
- NewAddon ([target], name[, options[, full[, ...]]])
-
Create a new AceAddon-3.0 addon.
Any library you specified will be embeded, and the addon will be scheduled for its OnInitializee and OnEnabled callbacks.
The final addon object, with all libraries embeded, will be returned.
Options table format:
* profile: choose the initial profile (if omittete, uses a per character one) * noswitch: disables Ace profile managemente, user will not be able to change it * nogui: do not generate a gui for configuration * nohelp: do not generate help (actually, help generation is not yet implemented) * enhancedProfile: adds "Switch all profiles to default" and "Remove unused profiles" do Ace profile gui
Parameters:
- target table to use as a base for the addon (optional) (optional)
- name string Name of the addon object to create
- options table options list (optional)
- full bool If true, all available and embeddable Ace3 library are embedded (optional)
- ... string List of libraries to embed into the addon (optional)
Returns:
-
table
new addon
Usage:
--Create a simple addon object MyAddon = LibStub("LibInit"):NewAddon("MyAddon", "AceEvent-3.0") -- Create a Addon object based on the table of a frame local MyFrame = CreateFrame("Frame") MyAddon = LibStub("LibInit"):NewAddon(MyFrame, "MyAddon", "AceEvent-3.0") -- Create an Addon based on the private table provided by Blizzard Code: local myname,addon = ... LibStub("LibInit"):NewAddon(addon,myname)
Compatibility
- GetCurrencyInfo (id)
-
Compatibility: Emulates renamed and modified GetCurrencyInfo
Parameters:
- id integer Currency identifier
Returns:
-
list
name,quantity,iconFiledID,quantityEarnedThisWeek,maxWeeklyQuantiti,maxQuantity,discovered,quality
- GetMissionInfo (id)
-
Compatibility: Emulates removed C_Garrison.GetMissionInfo
Parameters:
- id integer Mission ID
Returns:
-
list
location,xp,environment,environmentDesc,environmentTexture,locTextureKit,isExhausting,enemies
- Wrap (name)
-
Returns a closure to call a method as simple local function
Parameters:
- name string Method name
Returns:
-
func
Wrapper
Usage:
local print=self:Wrap("print") ; print("Hello") same as self:print("Hello")
Generic
- Colorize (stringa, colore)
-
Colors a string.
Parameters:
- stringa string A string
- colore string Name of a color (red, rare, alliance and so on). If not existent uses yellow
Returns:
-
string
Colored string
- GetBagSlotCount ()
-
Returns number of free bag slots and total bagt slots.
Returns:
- number Free bag slots
- number Total bag slots
- GetChatFrame ([chat=DEFAULT_CHAT_FRAME])
-
Return a named chatframe.
Returns nil if chat does not exist
Parameters:
- chat string Chat name (default DEFAULT_CHAT_FRAME)
Returns:
-
frame or nil
requested chat frame, can be nil if "chat" does not exist
- GetItemID (itemlink)
-
Parses an itemlink and returns itemId without calling API again
Parameters:
- itemlink string A standard wow itemlink
Returns:
-
number
itemId or 0
- GetTotalBagSlots ()
-
Return the total numner of bag slots
Returns:
-
number
Total bag slots
- Health (unit)
-
Returns unit's health as a normalized percent value
Parameters:
- unit string A standard unit name
Returns:
-
number
health as percent value
- Is (class, target)
-
Check if the unit in target hast the requested class
Parameters:
Returns:
-
boolean true if target has the requeste class
- NumericVersion ()
-
Returns a numeric representation of version.
Can be overridden
In default incarnation assumes that version is in the form x,y,z
Returns:
-
z+y*100+x*10000
- OnLeaveCombat (action[, ...])
-
Executes an action as soon as combat restrictions lift.
Action can be executed immediately if toon is out of combat
Parameters:
- action string or func To be executed, Can be a function or a method name
- ... mixed More parameters will be directly passed to action (optional)
- Parse (msg, n)
-
Parses a command from chat or from an table options handjer command
Internally calls AceConsole-3.0:GetArgs
Parameters:
- msg string or table Can be a string (when called from chat command) or a table (wbe called by Ace3 Options Table Handler)
- n number index in command list
Returns:
-
command,subcommand,arg,full string after command
- ScanBags ([index=0[, value=0[, startbag=0[, startslot=1]]]])
-
Scans Bags for an item based on different criteria
All parameters are optional.
With no parameters ScanBags returns the first empty slot
Passing starbag and scanslot allows to continue scanning after the first finding
Parameters:
- index number index in GetItemInfo result. 0 is a special case to match just itemid (default 0)
- value number value against to match. 0 is a special case for empty slot (default 0)
- startbag number Initialbag to start scan from (default 0)
- startslot number Initial slot to start scan from (default 1)
Returns:
- number ItemId
- number bag
- number slot
- list all return value from GetItemInfo called on _Itemid_
Or
-
bool
false If nothing found
Configuration panel
- AddToggle (flag, defaultvalue, name[, description=name[, icon]])
-
Create a boolean configuration var
Parameters:
- flag string variable name
- defaultvalue any
- name string public name (appears in gui)
- description string long description (appears in tooltip) (default name)
- icon string icon reference (optional)
Returns:
-
table
A reference to the newly create item inside Ace OptionTable
- Trigger (flag)
-
Simulates a configuration variable change.
Generates Apply* events if needed
Parameters:
- flag string Variable name
Hooks
- Empty (obj)
-
Implements PHP empty function.
Parameters:
- obj any variable to be tested
Returns:
-
boolean
- GetColorTable ()
-
Returns a crayon like object
Usage:
local C=LibStub("LibInit"):GetColorTable() C.Azure.c --returns a string "rrggbb" C.Azure.r --returns red value as a number C.Azure.g --returns green value as a number C.Azure.b --returns blue value as a number tostring(C.Azure) -- returns a string "rrggbb" "aa" .. C.Azure -- returns "aarrggbb" C.Azure() -- returns r,g,b as float list C.Azure.r -- returns r as float C("testo","azure") -- returns "|cff" .. >color code for azure> .. "test" .. "|r" -- For a list of available color check Colors -- Each color became the name of a meth
- GetFactory ()
-
Returns a factory for lightweight widgets
See also:
- GetKpairs ()
- Returns kpairs implementation Deprecated in favour of Wrap("Kpairs")
- LoadHelp ()
- Called to fill the help system
- OnDisabled ()
- Called from the OnDisable ACE event
- OnEmbedDisable ()
- Called when the wmbedding addon is disabled
- OnEmbedEnable (first)
-
Called When the embedding addon is enabled
Parameters:
- first
- OnEnabled ([first])
-
Called from the OnEnable ACE event
Parameters:
- first bool True on the first activation (optional)
- OnInitialized ()
- Called after VARIABLES_LOADED event, by OnInitialize Ace Hook
- Popup (msg[, timeout=60[, OnAccept[, OnCancel[, data[, StopCasting]]]]])
-
Show a popup
Display a popup message with Accept and optionally Cancel button
Parameters:
- msg string Message to be shown
- timeout number In seconds, if omitted assumes 60 (default 60)
- OnAccept func Executed when clicked on Accept (optional)
- OnCancel func Executed when clicked on Cancel (if nil, Cancel button is not shown) (optional)
- data mixed Passed to the callback function (optional)
- StopCasting bool If true, when the popup appear will stop any running casting. Useful to ask confirmation before performing a programmatic initiated spellcasting (optional)
- SetDbDefaults (tbl)
-
Called with the db default table as argument You can customize defaults here
Parameters:
- tbl table ACE DB default table
- SetOptionsTable (tbl)
-
Called with the current option table You can change the default options table here
Parameters:
- tbl table ACE Options Table
Coroutines
- NewDelayableTimer (callback)
-
Delayable timers
Create a timer that can be delayed. Useful for example for throttling sliders' events
This function just create the timer, to start (or delay) it use the :Start(seconds) method
Parameters:
- callback function Function to be called at expire time
Returns:
-
object
- coroutineExecute (interval, action[, combatSafe[, more]])
-
Generates and executes a coroutine with configurable interval and combat status
If called for already running coroutine changes the interval and the combat status
Parameters:
- interval number between steps
- action string or function To be executed, Can be a function or a method name
- combatSafe bool keep running in combat (optional)
- more mixed parameter are passed to function (optional)
Returns:
-
string
coroutine handle
- coroutineOnEnd (signature, action[, ...])
-
Executes an action as soon as a coroutine exit
Action can be executed immediately if coroutine is already dead
Parameters:
Automatic events
Usage:
function addon:EvtADDON_LOADED(event,addonname) end function addon:OnEnabled() self:StartAutomaticEvents() end function addon:OnDisabled() self:StopAutomaticEvents() end
- StartAutomaticEvents ()
- Starts all automatic events. Automatic events are the one for which exists and EvtEVENTNAME method
- StopAutomaticEvents ([ignore])
-
Stops all automatic events.
Automatic events are the one for which exists and EvtEVENTNAME method
Parameters:
- ignore string Name of an event method not to be stopped (optional)
Usage:
self:StopAutomaticEvents("ADDON_LOADED") -- Will stop all events but ADDON_LOADED