summaryrefslogtreecommitdiffstats
path: root/lib/format.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/format.lua')
-rw-r--r--lib/format.lua32
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/format.lua b/lib/format.lua
index 057bc03..1407b97 100644
--- a/lib/format.lua
+++ b/lib/format.lua
@@ -187,22 +187,22 @@ end
-- Takes a str and expands any ${...} constructs with the Lua variable
-- ex: a="foo"; print(expand_bash_syntax_vars("a=${a}) - > "a=foo"
-
-function expand_bash_syntax_vars ( str )
- 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)
+expand_bash_syntax_vars = function (str)
+
+ local deref = function ( f)
+ local v = getfenv(3) -- get the upstream global env
+ for w in string.gfind(f, "[%w_]+") do
+ if v then v = v[w] end
+ 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)
end
-- Removes the linenum line from str and replaces it with line.