Category: Libraries
Addon Information
Download Latest Version.
To add favorites please register for a free account. If you already have one you need to login. How do I install this? (FAQ)
AnduinLothar's Portal Bug Reports Feature Requests
Author:
Version:
2.1
Date:
04-16-2009 09:16 PM
Size:
4.46 Kb
Downloads:
605
Favorites:
9
MD5:
LibDefaults
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")
  Change Log - LibDefaults
v2.1
- Fixed a bug that broke non-table defaults

v2.0
- Added Meta-Indexing
Defaults are only saved in the default storage, not in the main table,
but still allows you to get them from the main table. Saves on run-time memory!
Defaults wont be accessable via pairs() from the main table,
unless you set the value to a non-default and then back to a default.
- Added Default Unloading
Removes defaults from the saved variables so that they aren't saved to disk. Speed up load time, yay!
- Added lib:Reset(addonName, varName) to reset an addons variable to default (and all table values to default)

v1.0
- Hopefully one version is enough!
  Archived Versions - LibDefaults
File Name
Version
Size
Author
Date
2.1
4kB
AnduinLothar
10-30-2008 12:07 AM
  Comments - LibDefaults
There have been no comments posted to this file.
Be the first to add one.



Category Jump:




The Network:
EQInterface | EQ2Interface | LoTROInterface | MMOInterface | War.MMOUI | WoWInterface | VGInterface | Allakhazam | Thottbot | Wowhead | Zam


©2009 MMOUI / ZAM Network
vBulletin - Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.