lua-users home
lua-l archive

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


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