[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Formatted input
- From: steve donovan <steve.j.donovan@...>
- Date: Tue, 23 Nov 2010 08:05:53 +0200
On Mon, Nov 22, 2010 at 11:55 PM, Dirk Laurie <[email protected]> wrote:
> line = "1.2e2 3.1416"
> x,y = line("%E%s+%F")
For output, it"s easy to hack the string metatable so that "%s =
%5.2f" % {"hello",math. pi} works as expected
see http://lua-users.org/wiki/StringInterpolation
getmetatable("").__mod = function(a, b)
if not b then
return a
elseif type(b) == "table" then
return string.format(a, unpack(b))
else
return string.format(a, b)
end
end
steve d.