-
Notifications
You must be signed in to change notification settings - Fork 0
Raw vs Proxy in LibSavedVars
LibSavedVars provides two different ways to access saved variable data:
- Proxy access — the normal interface used by addons.
- Raw access — direct access to the underlying ESO ZO_SavedVar data (which is itself a proxy we are not discussing here).
Understanding the difference is important when working with:
- Defaults.
- Migrations.
- Defaults trimming.
- Account-wide and character settings.
- Advanced saved data management.
A proxy is the normal LibSavedVars settings interface.
Example:
settings.enabled = true
local scale = settings.scaleThe proxy behaves like a normal Lua table, but internally LibSavedVars manages:
- Defaults.
- Account-wide storage.
- Character storage.
- Pinned account settings.
- Missing values.
- Data routing.
The addon works with the settings as if they were stored in one table.
Suppose the defaults are:
local defaults = {
enabled = true,
scale = 1.0,
}The actual SavedVariables table is empty:
{}Using the proxy:
settings.enabledreturns:
trueeven though there is no enabled entry in SavedVariables.
The value comes from:
Proxy
|
+-- Saved Data
|
+-- Defaults
if settings.enabled then
EnableFeature()
end
settings.scale = 1.25The addon does not need to know whether scale is stored:
- Account-wide.
- Character-specific.
- From defaults.
- Through a pinned key.
LibSavedVars handles the details.
Raw access exposes the actual saved data table.
Example:
local rawData = settings:GetRawDataTable()The raw table contains only values physically stored in SavedVariables.
Example:
Stored data:
{
scale = 1.25
}Raw access returns:
{
scale = 1.25
}It does not include defaults:
rawData.enabled
-- nilbecause enabled has never been saved.
Defaults:
{
enabled = true,
scale = 1.0,
}Saved data:
{
scale = 1.5,
}settings.enabledreturns:
truesettings.scalereturns:
1.5The proxy view is:
{
enabled = true,
scale = 1.5,
}local raw = settings:GetRawDataTable()returns:
{
scale = 1.5,
}Only explicitly stored values exist.
Proxy access should be used for normal addon operation.
Recommended for:
- Reading settings.
- Updating settings.
- UI options.
- Gameplay logic.
- User preferences.
Example:
settings.showMessages = falseThis is the preferred way to modify settings.
Raw access is intended for advanced operations.
Common uses:
- Writing migrations (used internally by migration helpers).
- Inspecting saved data.
- Debugging.
- Exporting settings.
- Cleaning saved data.
- Implementing custom conversion logic.
Example:
local raw = settings:GetRawDataTable()
if raw.oldSetting then
-- migrate old data
endMigrations normally operates on raw data.
Example:
Version 1:
{
oldName = true
}Version 2:
{
newName = true
}Migration:
settings:Migrate(2, function(savedVars)
savedVars.newName =
savedVars.oldName
savedVars.oldName = nil
end)The migration works with the stored structure.
Using the proxy would be incorrect because defaults and other behaviors may hide the actual stored state.
The difference between raw and proxy is especially important with defaults.
Example:
Defaults:
{
enabled = true
}New installation:
{}Proxy:
settings.enabledreturns:
trueRaw:
settings:GetRawDataTable().enabledreturns:
nilThe user has not saved the setting yet.
Defaults trimming removes stored values that match defaults.
Before trimming:
{
enabled = true,
scale = 1.5,
}Defaults:
{
enabled = true,
scale = 1.0,
}After trimming:
{
scale = 1.5,
}Proxy access remains:
settings.enabled
-- true
settings.scale
-- 1.5The user experience does not change.
Only the raw stored data changes.
LSV_Data adds another layer because settings may come from multiple sources.
Example:
Proxy View
LSV_Data
|
---------------------
| |
Account Settings Character Settings
|
Pinned Keys
The proxy provides a combined view.
Example:
settings.window.x
settings.theme
settings.buildmay internally come from different saved variable tables.
Raw access exposes the individual storage locations.
| Feature | Proxy | Raw |
|---|---|---|
| Normal addon access | Yes | No |
| Includes defaults | Yes | No |
| Shows stored values only | No | Yes |
| Handles account/character routing | Yes | No |
| Handles pinned settings | Yes | No |
| Used for migrations (internal) | Usually no | Yes |
| Used for debugging | Sometimes | Yes |
| User-facing settings | Yes | No |
Use the proxy interface when:
- Building addon features.
- Reading user preferences.
- Updating settings.
- Creating UI controls.
Use raw access when:
- Migrating data.
- Inspecting storage.
- Debugging saved variables.
- Performing cleanup.
- Working with the physical SavedVariables structure.
Avoid mixing the two approaches unnecessarily.
The proxy view represents:
"What value should my addon use?"
The raw view represents:
"What data has actually been saved?"
For most addon code, use the proxy.
For advanced saved data management, migrations, and diagnostics, use raw access.