lua-users home
lua-l archive

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


Thank you.
How about producing a empty string? 

string.format("Number is %d",data) ==> Number is


----- Original Message ----- 
From: "Andreas Stenius" <kaos@explosive.se>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Thursday, August 24, 2006 4:09 PM
Subject: Re: string.format a nil value


> jason zhang skrev:
> [snip]
>> string.format("%d",novalue), where novalue is a nil variant.
>>  
>> Why not outputing a "NIL" like string? It think it's not very friendly 
>> to print a error information and
>> exit.
> 
> Because code that uses the output may rely on the facy that it should be
> a valid number, since %d was used. If you want "nil" to come out of it,
> i would recommend trying:
> 
> string.format("%s", tostring(novalue))
> 
> Which will work as expected for numbers as well (altough you'll get the
> fraction part as well, which isn't what you'd get with %d)..
> 
> Cheers,
> Andreas
> 
>