-
Notifications
You must be signed in to change notification settings - Fork 0
Public API Reference
This section documents the public API provided by LibSavedVars. The public API is the supported interface addon developers should use when creating, accessing, and managing saved variables.
Internal implementation functions and classes are not covered here and may change between library versions.
LibSavedVars provides APIs for:
- Creating account-wide saved variables.
- Creating character-specific saved variables.
- Managing defaults.
- Handling version upgrades and migrations.
- Switching between account-wide and character settings.
- Pinning selected settings to account-wide storage.
- Accessing raw saved variable data.
- Iterating over active settings.
Creates an account-wide saved variables object.
local settings = LibSavedVars:NewAccountWide(
savedVariableName,
version,
namespace,
defaults
)| Parameter | Type | Description |
|---|---|---|
savedVariableName |
string | ESO SavedVariables table name. |
version |
number | Current saved data version. |
namespace |
string/nil | Optional namespace within the saved variables table. |
defaults |
table | Default settings values. |
A saved variables object.
local settings = LibSavedVars:NewAccountWide(
"MyAddonSavedVariables",
1,
nil,
defaults
)Creates character-specific saved variables.
local settings = LibSavedVars:NewCharacterSettings(
savedVariableName,
version,
namespace,
defaults
)Same as NewAccountWide().
A character-specific saved variables object.
local settings = LibSavedVars:NewCharacterSettings(
"MyAddonSavedVariables",
1,
nil,
defaults
)Saved variables returned by LibSavedVars behave like normal Lua tables.
local enabled = settings.enabledIf the value has not been saved, LibSavedVars returns the value from the defaults table.
settings.enabled = falseValues are automatically persisted by ESO during normal saved variable processing.
Nested tables can be accessed directly.
settings.window.position.x = 200Enables automatic removal of saved values that match defaults.
settings:EnableDefaultsTrimming()When enabled, values equal to their default values are removed before saving. These values are restored automatically from the defaults table when the addon loads.
settings:EnableDefaultsTrimming()Registers a migration callback for a specific version.
settings:Migrate(version, callback)| Parameter | Type | Description |
|---|---|---|
version |
number | Version produced by this migration. |
callback |
function | Function that updates saved data. |
settings:Migrate(2, function(savedVars)
savedVars.newSetting = savedVars.oldSetting
savedVars.oldSetting = nil
end)- Migrations run only when the stored version is lower than the migration version.
- Multiple migrations execute in ascending version order.
- Migration functions should update only the data required for their version.
LSV_Data provides advanced management for addons that support both account-wide and character-specific settings.
Returns the currently active settings table.
local settings = data:GetActiveSavedVars()| Type | Description |
|---|---|
| table | Active settings table. |
Selects whether account-wide settings are active.
data:SetAccountSavedVarsActive(accountActive)| Parameter | Type | Description |
|---|---|---|
accountActive |
boolean |
true for account-wide settings, false for character settings. |
data:SetAccountSavedVarsActive(true)Returns the current storage mode.
local accountActive = data:GetAccountSavedVarsActive()| Type | Description |
|---|---|
| boolean |
true if account-wide settings are active. |
Pins a setting key to account-wide storage.
data:AddAccountWideToggle(key)| Parameter | Type | Description |
|---|---|---|
key |
string | Setting key to store account-wide. |
data:AddAccountWideToggle("window")Pinned keys remain stored in account-wide settings even when character settings are active.
Marks a setting as character-specific.
data:AddCharacterSettingsToggle(key)| Parameter | Type | Description |
|---|---|---|
key |
string | Setting key to store per character. |
Returns an iterator over the active settings.
for key, value in data:GetIterator() do
-- process setting
endProvides a merged view of active settings, including pinned account-wide keys.
Returns the underlying stored data table.
local rawData = settings:GetRawDataTable()Unlike normal settings access, this returns only values actually stored in SavedVariables.
Useful for:
- Debugging.
- Writing migrations.
- Inspecting saved data.
- Exporting settings.
LibSavedVars provides helper functions for common saved data operations.
Common operations include:
- Creating missing table paths.
- Moving values.
- Copying values.
- Removing obsolete settings.
- Migrating between account-wide and character storage.
These utilities are intended for use inside migration callbacks.
Example:
settings:Migrate(3, function(savedVars)
-- migration operations
end)LibSavedVars performs saved variable management during addon initialization and ESO save events.
Addon authors should:
- Create saved variables during initialization.
- Register migrations immediately after creation.
- Avoid manually modifying the underlying SavedVariables tables.
- Allow LibSavedVars to manage persistence.
The functions documented in this section are considered the supported public API.
Developers should avoid depending on:
- Internal tables.
- Private fields.
- Undocumented helper functions.
- Internal class implementation details.
Using the public API ensures compatibility with future LibSavedVars releases.
| Function | Purpose |
|---|---|
NewAccountWide() |
Create account-wide settings |
NewCharacterSettings() |
Create character settings |
EnableDefaultsTrimming() |
Remove redundant default values |
Migrate() |
Register saved data migrations |
GetActiveSavedVars() |
Get current active settings |
SetAccountSavedVarsActive() |
Switch storage mode |
GetAccountSavedVarsActive() |
Check storage mode |
AddAccountWideToggle() |
Pin keys to account storage |
AddCharacterSettingsToggle() |
Pin keys to character storage |
GetIterator() |
Iterate active settings |
GetRawDataTable() |
Access stored values only |
This API provides the building blocks needed to manage simple settings as well as complex, evolving saved data structures.