[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: __tostring and string.format
- From: HyperHacker <hyperhacker@...>
- Date: Sun, 5 Dec 2010 21:45:47 -0700
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.