lua-users home
lua-l archive

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

True, :) if the output is to user interface directly. But string.format could be used also for interim, or technical files etc. and - 'true' and 'false' are already defined like that (lower case) as Lua keywords.


David Morris-Oliveros kirjoitti 2.8.2006 kello 10.39:

Yes true, but it's also locale dependant.
In english, it's true/false, spanish, verdadero/falso, etc...
There's little room for locale in numbers (*), but the concept of true/false is not directly printable. There is no universal symbol for true or false...
(And that's why booleans are not coercible).

(*) Though the printing of decimals does vary a bit, for example:
English: 14/10 = 1.4
Spanish: 14/10 = 1,4

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

On 8/2/06, Torsten Karwoth <> 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)
> return bu(1+1 == 2)




// david morris-oliveros
// camera & lua coder