[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string.format
- From: Torsten Karwoth <agonizer@...>
- Date: Wed, 2 Aug 2006 09:19:35 +0200
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