libs/core: Add Pythonic string formatting syntax
authorSteven Barth <steven@midlink.org>
Sun, 24 Aug 2008 16:35:06 +0000 (16:35 +0000)
committerSteven Barth <steven@midlink.org>
Sun, 24 Aug 2008 16:35:06 +0000 (16:35 +0000)
libs/core/luasrc/util.lua

index d8fc666233da71e8056bf55a8f4483dbf993e6bb..cc15d3aeb5626c6c904e1197a04cd257e4834d63 100644 (file)
@@ -27,6 +27,20 @@ limitations under the License.
 --- LuCI utility functions.
 module("luci.util", package.seeall)
 
+--
+-- Pythonic string formatting extension
+--
+getmetatable("").__mod = function(a, b)
+       if not b then
+               return a
+       elseif type(b) == "table" then
+               return a:format(unpack(b))
+       else
+               return a:format(b)
+       end
+end
+
+
 --
 -- Class helper routines
 --