Go to Page... |
Updated: | 04-16-09 07:16 PM |
Created: | 10-26-08 03:34 PM |
Downloads: | 2,423 |
Favorites: | 9 |
MD5: |
This small library lets you register saved variable defaults which it sets only if the variable is nil when it loads. You can also register functions to fire after the variables of an addon have been loaded and initialized.
For advanced usage, you can also set n-deep table value defaults. If the containing tables don't exist they will be automatically created.
lib:SetDefault(addonName, varName, ...)
Register a saved variable's default value.
For non-tables:
if the variable is nil once the addon's saved variables are loaded, it will be set to the default value.
For tables:
The variable will be set to an empty table which is meta-index-linked to the stored default table.
Any time you access keys in the table the default will be returned, unless you set that key to a non-default value.
This saves space in live memory because the defaults only reside in one place.
With the drawback that #, pairs and ipairs will not count the default values.
SetDefault also gives you the option to build your defaults on the fly without creating the containing tables.
It can handle N-depth table values by providing any number of keys. ex: _G["SavedVarName"][key1][key2] = value
The addon saved variable defaults will be initialized at the addon's ADDON_LOADED event,
or they can be forced to load using lib:InitAddOn(addonName).
Usage:
lib:SetDefault("MyAddOn", "SavedVar(Table)Name", [key1, [key2, [...] ] ], value)
Example Usage:
local lib = LibStub("LibDefaults")
lib:SetDefault("MyAddOn", "SavedVarName", SavedVarValue)
lib:SetScript(addonName, func)
Register a function to be executed once an addon's variables have been loaded.
Fires after addon defaults have been initialized.
Usage:
lib:SetScript("MyAddOn", function)
Example Usage:
local lib = LibStub("LibDefaults")
lib:SetScript("MyAddOn", function(addonName) dostuff() end)
lib:Reset(addonName, varName)
Reset you addon's global variable back to default.
Also recursively resets all table values and sub-tables.
Usage:
lib:SetDefault("MyAddOn", "SavedVar(Table)Name")
Example Usage:
local lib = LibStub("LibDefaults")
lib:SetDefault("MyAddOn", "SavedVarName")
There have been no comments posted to this file.
Be the first to add one. |