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

lume.format(str, table) doesn't properly handle false values #35

Open
wolf81 opened this issue Apr 21, 2021 · 3 comments
Open

lume.format(str, table) doesn't properly handle false values #35

wolf81 opened this issue Apr 21, 2021 · 3 comments

Comments

@wolf81
Copy link

wolf81 commented Apr 21, 2021

Simple test:

local t = lume.format("{1} is {2} is {3}", { true, false, true })
print(t) -- true is {2} is true

I guess this is of the way Lua deals with false values, not sure what a proper fix would be, but if I can figure one out I will send a PR.

@NQMVD
Copy link

NQMVD commented Aug 15, 2023

I know it's an old Issue but i fixed it on my fork by modifying the f function like so:

local f = function(x)
  local index = tonumber(x)
  if index then
    return tostring(vars[index])
  else
    return tostring(vars[x])
  end
end

and it works now:

print(lume.format("{1} is {2} and {f}", {true, false, f=false}))
-- prints true is false and false

it just prints nil in case of 'not found' now

@wolfgang-ironsoftware
Copy link

wolfgang-ironsoftware commented Aug 15, 2023

@ItsNMB Very nice if it works - I hope to check it in the couple of weeks. I still use Lua/LOVE/lume in hobby projects, so if your fix works, it will be useful to me :)

And maybe your approach gave me an idea for an even cleaner fix ... hmm..

@wolf81
Copy link
Author

wolf81 commented Feb 20, 2024

@ITSN

I know it's an old Issue but i fixed it on my fork by modifying the f function like so:

local f = function(x)
  local index = tonumber(x)
  if index then
    return tostring(vars[index])
  else
    return tostring(vars[x])
  end
end

and it works now:

print(lume.format("{1} is {2} and {f}", {true, false, f=false}))
-- prints true is false and false

it just prints nil in case of 'not found' now

Hi, it's been a long time to verify and respond and yes, your approach fixes the issues with booleans.

It makes 3 tests fail though. Maybe the tests should be adjusted.

I'll probably use your approach in my fork as well, after I've fixed tests.

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

No branches or pull requests

3 participants