lua-users home
lua-l archive

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


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.