Skip to content
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

Fix issue #135 #136

Merged
merged 5 commits into from
Jan 6, 2023
Merged

Fix issue #135 #136

merged 5 commits into from
Jan 6, 2023

Conversation

saccarosium
Copy link
Collaborator

Now opt should work as expected.

@savq
Copy link
Owner

savq commented Jan 6, 2023

Just for future reference, the tri-state map of opt is:

cfg \ args 1 0 nil
1 1 0 1
0 1 0 0

We can ignore the case cfg.opt == nil because cfg will always have a default value. One way to simplify this would be:

local opt = args.opt or cfg.opt and args.opt == nil

This is very similar to your suggestion. Although it's clearer to check for == nil instead of ~= false because we're interested in the case cfg.opt == true and args.opt == nil.

We can test this is the correct behavior with the following snippet:

local co = coroutine

local states = co.wrap(function()
  co.yield(false, false)
  co.yield(false, true)
  co.yield(false, nil)
  co.yield(true, false)
  co.yield(true, true)
  co.yield(true, nil)
  return
end)

for c, a in states do
  local opt = a or c and a == nil
  print(string.format("c = %s; a = %s; opt = %s", c, a, opt))
end

Which outputs:

c = false; a = false; opt = false
c = false; a = true; opt = true
c = false; a = nil; opt = false
c = true; a = false; opt = false
c = true; a = true; opt = true
c = true; a = nil; opt = true

lua/paq.lua Outdated Show resolved Hide resolved
@saccarosium
Copy link
Collaborator Author

Should be ok

@savq savq merged commit 6506548 into savq:master Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants