-
Notifications
You must be signed in to change notification settings - Fork 0
Public API Reference
This section provides a reference for the public LibSavedVars API. It is intended for addon developers who need detailed information about available functions, parameters, and return values.
The API is organized into several areas:
Creating saved variables.
Accessing and managing saved data.
Account-wide and character settings.
Versioning and migrations.
Defaults management.
Advanced data management.
For most addons, only the creation functions and basic table access are required.
Creates an account-wide saved variables object.
local settings = LibSavedVars:NewAccountWide(
savedVariableName,
version,
namespace,
defaults
)
data:AddAccountWideToggle("window")
Returns an iterator over the active settings.
for key, value in data:GetIterator() do
-- use setting
end
Provides a combined view of active settings, including pinned account-wide values.
Returns the underlying SavedVariables table without default-value resolution.
local raw = settings:GetRawDataTable()
Useful for:
Debugging.
Inspecting saved values.
Migration work.
Data export.
The returned table contains only values actually stored in SavedVariables.
LibSavedVars includes helper functions for common migration tasks, including:
Moving data between account-wide and character storage.
Creating missing table paths.
Removing obsolete settings.
Copying values between locations.
These functions are intended for advanced migration scenarios where manually modifying tables would be error-prone.
A typical addon initialization follows this pattern:
local defaults = {
enabled = true,
scale = 1.0,
}
local settings = LibSavedVars:NewAccountWide(
"MyAddonSavedVariables",
1,
nil,
defaults
)
settings:EnableDefaultsTrimming()
settings:Migrate(2, function(savedVars)
-- version 2 migration
end)
After initialization, the addon should use settings throughout its code rather than accessing the underlying SavedVariables directly.
When using LibSavedVars:
Create saved variables once during addon initialization.
Treat defaults as a template, not storage.
Increase versions only when existing data changes.
Keep migrations small and independent.
Use
LSV_Dataonly when multiple storage models are required.Avoid depending on the internal SavedVariables structure unless using advanced APIs.
Following these practices keeps saved data stable, upgradeable, and easy to maintain.