Quantcast GetNewSavedVars() mishandled optional namespace argument - ESOUI
Thread Tools Display Modes
07/26/18, 08:22 AM   #1
SDPhantom
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 39
GetNewSavedVars() mishandled optional namespace argument

Code:
ZO_SavedVars:New("TestSV",1,{},"TestProfile");
Running this despite an attempt to handle namespace as an optional argument causes an error in trying to access "TestProfile" as the defaults table instead of a string. This is caused by GetNewSavedVars() checking the wrong argument being nil.



EsoUI\Libraries\Utility\ZO_SavedVars.lua:143
Code:
if defaults == nil and type(namespace) == "table" then
defaults should at least be changed to profile since in this case, that's the argument that's nil.
Code:
if profile == nil and type(namespace) == "table" then


Preferably, there shouldn't be a check for nil there anyway since the following code block handles rearranging the arguments into the correct places. Stopping this from happening causes this error in the first place. The down side to removing this check? You ignore a value that should be discarded anyway.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
07/26/18, 08:50 AM   #2
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,661
Maybe I got you wrong but you tried to use namespace as an "optional argument". So why don't you just put nil in the correct place as you call the function?
Lua Code:
  1. ZO_SavedVars:New("TestSV",1, nil, {},"TestProfile")

Edit:
Oh sorry just saw the lines 142ff in the sourcecode and now I understood what you are up to


Lua Code:
  1. --namespace is an optional argument
  2.     if defaults == nil and type(namespace) == "table" then
  3.         profile = defaults
  4.         defaults = namespace        
  5.         namespace = nil
  6.     end
  7.     profile = profile or "Default"
  8.     if type(profile) ~= "string" then
  9.         error("Profile must be a string or nil")
  10.     end




Here are the prameters of the function GetNewSavedVars from the live server:
Lua Code:
  1. local function GetNewSavedVars(savedVariableTable, version, namespace, defaults, profile, displayName, characterName, characterId, characterKeyType)

Parameters of ZO_SavedVars:New()
Lua Code:
  1. function ZO_SavedVars:New(savedVariableTable, version, namespace, defaults, profile, displayName, characterName, characterId, characterKeyType)


If you use ZO_SavedVars:New from your example:
Lua Code:
  1. ZO_SavedVars:New("TestSV",1,{},"TestProfile")

savedVariableTable: "TestSV"
version: 1
namespace: {}
defaults: "TestProfile"
profile: nil

Last edited by Baertram : 07/26/18 at 08:53 AM.
  Reply With Quote
07/26/18, 01:35 PM   #3
SDPhantom
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 39
The syntax is also noted near the top of the file as:
Code:
local sv = ZO_SavedVars:New(savedVariableTable, version, [, namespace], defaults [, profile])
I actually discovered it by glancing over the code and found a spot that "didn't look right". The example, I made up by working backwards through the code to build a case where something follows the syntax for the API, but throws an error when run.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

ESOUI » Developer Discussions » Bug Reports » GetNewSavedVars() mishandled optional namespace argument

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off