lua-users home
lua-l archive

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


Sunday, October 1, 2006, 11:50:56 PM, David Burgess wrote:

> Seems %m or %t (tostring) would be a fair incremental improvement at little
> cost.

Yes. Here is the case to add in str_format()...

        case 't': {
          size_t l = strlen(form);
          form[l - 1] = 's';
          lua_getglobal(L, "tostring");
          lua_pushvalue(L, arg);
          lua_call(L, 1, 1);
          lua_replace(L,arg);
          /* fall into... */
        }
        case 's': {

Regards,

e

> On 10/2/06, Doug Currie <doug.currie@gmail.com> wrote:
>> Monday, September 11, 2006, 12:32:09 PM, Roberto Ierusalimschy wrote:
>>
>> >> i have seen some lua 5.2 feature requests. is there an "official" place
>> >> where the feature requests are stored/tracked?
>>
>> > Only the list itself.
>>
>> Here is a proposal for 5.2...
>>
>> It was a surprise to me that string.format()'s option "%s" did not
>> apply tostring() to its arguments as print() does.
>>
>> This would make formatted output using, e.g., loadable numerics
>> libraries like decNumber, much more convenient. Of course, it would
>> work with any userdata or class that implemented __tostring.
>>
>> So, my request is that Lua 5.2 either
>> - apply tostring() to non-string "%s" arguments of string.format(), or
>> - add a string.format option that applies tostring() to its argument,
>> and then performs the usual "%s" action.
>>
>> If the second approach is preferred, I am not particular to any
>> specific character to specify this format option, though I recommend
>> "%m" (use Metatable's __tostring) or "%y" (stringifY) -- neither of
>> these is in common usage with printf as far as I know, unlike "%o"
>> (Object) and "%S" (wide String).

-- 
Doug Currie
Londonderry, NH