[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string.format a nil value
- From: Andreas Stenius <kaos@...>
- Date: Thu, 24 Aug 2006 10:09:46 +0200
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