create util
This commit is contained in:
@@ -1,13 +1,8 @@
|
|||||||
-- got from http://lua-users.org/wiki/StringInterpolation
|
local util = require "zenbones.util"
|
||||||
function interp(s, tab)
|
|
||||||
return (s:gsub("($%b{})", function(w)
|
|
||||||
return tab[w:sub(3, -2)] or w
|
|
||||||
end))
|
|
||||||
end
|
|
||||||
|
|
||||||
local function write_template(path, template, values)
|
local function write_template(path, template, values)
|
||||||
print("[write template] " .. path)
|
print("[write template] " .. path)
|
||||||
local content = interp(template, values)
|
local content = util.interp(template, values)
|
||||||
local file = io.open(path, "w")
|
local file = io.open(path, "w")
|
||||||
file:write(content)
|
file:write(content)
|
||||||
file:close()
|
file:close()
|
||||||
|
|||||||
10
lua/zenbones/util.lua
Normal file
10
lua/zenbones/util.lua
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user