lua-users home
lua-l archive

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


On Sun, Dec 5, 2010 at 8:45 PM, HyperHacker <hyperhacker@gmail.com> wrote:
> Something that always bugged me:
>> t={}
>> setmetatable(t, {__tostring = function(t) return "xxx" end})
>> print(t)
> xxx
>> print(('%s'):format(t))
> stdin:1: bad argument #1 to 'format' (string expected, got table)
>
> Why does string.format not call tostring() on arguments given as %s?
> (and for that matter tonumber() for %d/%u, which in turn could call a
> __tonumber metamethod...)
>
> --
> Sent from my toaster.
>
>

I had never noticed that, but it's a good idea. As for __tonumber, I
was thinking about that too, and I'd like to see it just for parity
with __tostring.

~Jonathan