lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Given that we have modifiers for strings and numbers, I would
have thought for completness booleans was appropraite.

On 8/2/06, Torsten Karwoth <agonizer@gmx.de> wrote:
Am Mittwoch, 2. August 2006 03:16 schrieb D Burgess:
> I just noticed that string.format is missing an option (I think),
> namely, a boolean option.
>
> How about -
>
> %b -> "true" or "false"
> %bc -> "True" or "False"
> %bu -> "TRUE" or "FALSE"
> %b0 -> 0 or 1
>
> David B.

I dont think so. Lua is designed to handle such things easy. Your
suggestion would complicate it a little bit,IMHO to much effort
and to little use.

local b  = function(Test) return Test and "true" or "false"; end
local bc = function(Test) return Test and "True" or "False"; end
local bu = function(Test) return Test and "TRUE" or "FALSE"; end
...
print(string.format("%s %s %s\n", b(false), bc(false), bu(false)));
print(string.format("%s %s %s\n", b(true), bc(true), bu(true)));

false False FALSE
true True TRUE

> return bu(1 == 2)
FALSE
> return bu(1+1 == 2)
TRUE
>


HTH

  Torsten