summaryrefslogtreecommitdiff
path: root/lualibs-util-tpl.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lualibs-util-tpl.lua')
-rw-r--r--lualibs-util-tpl.lua8
1 files changed, 8 insertions, 0 deletions
diff --git a/lualibs-util-tpl.lua b/lualibs-util-tpl.lua
index dcc4c12..e0c405a 100644
--- a/lualibs-util-tpl.lua
+++ b/lualibs-util-tpl.lua
@@ -159,6 +159,14 @@ end
templates.replace = replace
+function templates.replacer(str,how,recurse) -- reads nicer
+ return function(mapping)
+ return lpegmatch(replacer,str,1,mapping,how or "lua",recurse or false) or str
+ end
+end
+
+-- local cmd = templates.replacer([[foo %bar%]]) print(cmd { bar = "foo" })
+
function templates.load(filename,mapping,how,recurse)
local data = io.loaddata(filename) or ""
if mapping and next(mapping) then