From 58060aaf73ba40b69f0d254ee0b9fa26682d5d77 Mon Sep 17 00:00:00 2001 From: Michael Chris Lopez Date: Tue, 21 Sep 2021 16:47:35 +0800 Subject: [PATCH] create util --- lua/zenbones/build.lua | 9 ++------- lua/zenbones/util.lua | 10 ++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 lua/zenbones/util.lua diff --git a/lua/zenbones/build.lua b/lua/zenbones/build.lua index e909be2..e9206dd 100644 --- a/lua/zenbones/build.lua +++ b/lua/zenbones/build.lua @@ -1,13 +1,8 @@ --- got from http://lua-users.org/wiki/StringInterpolation -function interp(s, tab) - return (s:gsub("($%b{})", function(w) - return tab[w:sub(3, -2)] or w - end)) -end +local util = require "zenbones.util" local function write_template(path, template, values) print("[write template] " .. path) - local content = interp(template, values) + local content = util.interp(template, values) local file = io.open(path, "w") file:write(content) file:close() diff --git a/lua/zenbones/util.lua b/lua/zenbones/util.lua new file mode 100644 index 0000000..f2dc4d4 --- /dev/null +++ b/lua/zenbones/util.lua @@ -0,0 +1,10 @@ +local M = {} + +-- got from http://lua-users.org/wiki/StringInterpolation +function M.interp(s, tab) + return (s:gsub("($%b{})", function(w) + return tab[w:sub(3, -2)] or w + end)) +end + +return M