From 1e465e49670f6c0fccc1cd920992a14942d3cfba Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 11:19:09 +0100 Subject: expand variables --- misc/freeswitch/scripts/dialplan/router.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan/router.lua') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 6c5b9f1..5f427ac 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -52,21 +52,20 @@ function Router.read_table(self, table_name) end -function Router.expand_variables(self, line) - return (line:gsub('{([%a%d_]+)}', function(captured) - return variables[captured] or ''; +function Router.expand_variables(self, line, variables) + return (line:gsub('{([%a%d%._]+)}', function(captured) + return common.str.try(variables, captured) or ''; end)) end function Router.element_match(self, pattern, search_string, replacement) - local variables_list = {}; local success, result = pcall(string.find, search_string, pattern); if not success then self.log:error('ELEMENT_MATCH - table error - pattern: ', pattern, ', search_string: ', search_string); elseif result then - return true, search_string:gsub(pattern, self:expand_variables(replacement, variables_list)); + return true, search_string:gsub(pattern, self:expand_variables(replacement, self.variables)); end return false; @@ -109,7 +108,7 @@ function Router.route_match(self, route) if element.action ~= 'none' then if common.str.blank(element.var_in) or common.str.blank(element.pattern) and element.action == 'set' then result = true; - replacement = element.replacement; + replacement = self:expand_variables(element.replacement, self.variables); else local command, variable_name = common.str.partition(element.var_in, ':'); -- cgit v1.2.3