lua-users home
lua-l archive

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



> Am 15.10.2019 um 16:43 schrieb Lorenzo Donati <lorenzodonatibz@tiscali.it>:
> 
> On 15/10/2019 14:14, Marc Balmer wrote:
>> Hi
>> 
>> In lstrlib.c, the preprocessor define FLAGS defines the flag
>> characters that be used in string formatting (string.format()). It
>> includes flags like 0, -, space, etc.  The flag to add thousands
>> separators to a number ('), however, is missing.  Is there a reason
>> for that?
>> 
>> I can use
>> 
>> print(string.format("%.2f", 1000000))
>> 
>> to print a number,  but with "stock" Lua I can not use
>> 
>> print(string.format("%'.2f", 1000000))
>> 
>> to print the number with thousands separator.
>> 
>> Adding an apostrophe to FLAGS in lstrlib.c makes it perfectly word.
>> 
>> I understand that the thousands separator flag is not part of C89,
>> but a SuSv2 extension, which seems to be present on almost all
>> (modern) operating systems.
>> 
> 
> I don't think it is part of ANY C standard, if I read correctly the info
> at cppreference.com:
> 
> https://en.cppreference.com/w/c/io/fprintf

As I wrote, it is a SUSv2 extension...
> 
> Although I consider that a very useful feature, messing with the default flags could be dangerous for code compatibility IMO, as long as
> Lua delegates the underlying formatting to C libraries.
> 
> Should Lua ever implemented a more complete string formatting facility, I'd welcome that feature.
> 
>> Could FLAGS be something that could be overriden in luaconf.h?  It
>> would be as simple as enclosing the definition of FLAGS in a #ifndef
>> FLAGS / #endif bracket.
>> 
>> Thanks, Marc
>> 
>> 
>> 
> 
> cheers!
> 
> -- Lorenzo
>