lua-users home
lua-l archive

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


On 21 July 2015 at 20:48, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2015-07-21 6:49 GMT+02:00 Tim Hill <drtimhill@gmail.com>:
>
>>> On Jul 20, 2015, at 6:59 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>>If you view string.format() as a thin wrapper for sprintf(), then it’s unlikely to
>> change.
>
> It's not that thin. There is a separate case for every specifier. At present
> the following are all treated the same.
>
>         case 'd': case 'i':
>         case 'o': case 'u': case 'x': case 'X': {
>           lua_Integer n = luaL_checkinteger(L, arg);
>           addlenmod(form, LUA_INTEGER_FRMLEN);
>           nb = sprintf(buff, form, n);
>           break;
>         }
>
>> I doubt a re-write of sprintf() is high on Roberto’s todo list. Though is
>> IS quite high on my list, I wonder if others here would be interested
>> in such a facility?
>
> The OP's problem can be solved with something much less ambitious.
> Replace the first line above by:
>
>       case 'd':
>           lua_Integer n = (lua_Integer)luaL_checknumber(L, arg);
>           addlenmod(form, LUA_INTEGER_FRMLEN);
>           nb = sprintf(buff, form, (n);
>           break;
>       case 'i':
>
> My question was: which of the other five cases should also be
> treated like case 'd?
>

IIUC, this would break it for some numbers between 2^53 and 2^63