ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Bug Reports (https://www.esoui.com/forums/forumdisplay.php?f=187)
-   -   [outdated] GetNewSavedVars() mishandled optional namespace argument (https://www.esoui.com/forums/showthread.php?t=7956)

SDPhantom 07/26/18 08:22 AM

[outdated] 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.

Baertram 07/26/18 08:50 AM

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

SDPhantom 07/26/18 01:35 PM

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.


All times are GMT -6. The time now is 09:33 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI