summaryrefslogtreecommitdiffstats
path: root/lib/format.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/format.lua')
-rw-r--r--lib/format.lua29
1 files changed, 14 insertions, 15 deletions
diff --git a/lib/format.lua b/lib/format.lua
index e19899f..6de19c4 100644
--- a/lib/format.lua
+++ b/lib/format.lua
@@ -179,7 +179,7 @@ function md5sum_string ( str)
local checksum = {}
for line in f:lines() do
checksum[#checksum + 1] = line
- end
+ end
f:close()
return checksum[1]
end
@@ -189,21 +189,20 @@ end
-- ex: a="foo"; print(expand_bash_syntax_vars("a=${a}) - > "a=foo"
expand_bash_syntax_vars = function ( str )
+ local deref = function ( f)
+ local v = _G
+ for w in string.gfind(f, "[%w_]+") do
+ v = v[w]
+ end
+ return v
+ end
- local deref = function ( f)
- local v = _G
- for w in string.gfind(f, "[%w_]+") do
- v = v[w]
- end
- return v
- end
-
- for w in string.gmatch (str, "${[^}]*}" ) do
- local rvar = string.sub(w,3,-2)
- local rval = ( deref(rvar) or "nil" )
- str = string.gsub (str, w, rval)
- end
- return (str)
+ for w in string.gmatch (str, "${[^}]*}" ) do
+ local rvar = string.sub(w,3,-2)
+ local rval = ( deref(rvar) or "nil" )
+ str = string.gsub (str, w, rval)
+ end
+ return (str)
end
-- Removes the linenum line from str and replaces it with line.