New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for tables for default in AuthorOptions #999
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will work, but it should be recursive to be fully correct.
WeakAurasOptions/AuthorOptions.lua
Outdated
@@ -1147,13 +1147,26 @@ end | |||
|
|||
local function allChoicesAreDefault(data) | |||
for _, option in ipairs(data.authorOptions) do | |||
if option.key ~= nil and option.default ~= nil and option.default ~= data.config[option.key] then | |||
if option.key ~= nil and option.default ~= nil and (option.default ~= data.config[option.key] or compareTables(option.default, data.config[option.key])) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work because the logic is the wrong way around. You want to check if the tables are different.
Also this will not work if you are comparing two indentical values, as in that case compareValues is called with two values, and calling pairs on that will result in a error.
I believe that should do it. It's recursive and fixes the logic for checking if the values match. |
WeakAurasOptions/AuthorOptions.lua
Outdated
local function allChoicesAreDefault(data) | ||
for _, option in ipairs(data.authorOptions) do | ||
if option.key ~= nil and option.default ~= nil and option.default ~= data.config[option.key] then | ||
return false | ||
return tablesAreEqual(option.default, data.config[option.key]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop needs to continue if the values are equal. It should only return false if the values are not equal.
Also your function also checks for equality for non-table values, so the original check "option.default ~= data.config[option.key]" should not be necessary.
We might have a table comparing equal function already somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, sorry. Latest commit should (finally) be correct.
WeakAurasOptions/AuthorOptions.lua
Outdated
if option.key ~= nil and option.default ~= nil and option.default ~= data.config[option.key] then | ||
return false | ||
end | ||
if option.key ~= nil and option.default ~= nil then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if option.key ~= nil and option.default ~= nil then
- if tablesAreEqual(option.default, data.config[option.key]) then
- elseif option.default ~= data.config[option.key] then
+ if not tablesAreEqual(option.default, data.config[option.key]) then
return false
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's still not quite correct, but your if branch was too complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yeah that's more simple.
Why is that not correct? With that, it still returns true/false as it should, right (looking at the example inputs from my latest comment)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, for one thing, you can simply check that the option class is not noninteractive
(see the top of the file), instead of checking that the key and default aren't nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right it's indeed correct. But that's not how that check should be written. A if, whose only purpose is to act as a additional check for the elseif branch is unnecessarily complex.
With that latest commit, it does only exit the loop when it finds something unequal. For example: Say the function is passed Say it's passed Pass Pass Apologies if I'm being difficult, but I'm fairly sure that's correct. Edit: Main thing is that |
Alright, that's my last try. If that doesn't work I'll give up and let you guys do it :P |
I pushed a fix to your whitespace (you should install editorconfig so that it's taken care of for you) |
Thanks, merged now. |
Fixes #998