Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
local log = require "resources.functions.log".apply_var
function apply_global_var(str, t)
return (string.gsub(str, "$${.-}", function(key)
key = string.sub(key, 4, -2)
local var = t and t[key] or freeswitch.getGlobalVariable(key)
if not var then
log.warningf("unknown global variable: %s", key)
end
return var or ''
end))
end
function apply_session_var(str, t)
return (string.gsub(str, "${.-}", function(key)
key = string.sub(key, 3, -2)
local var = t and t[key] or freeswitch.getGlobalVariable(key)
return var or ''
end))
end
function apply_var(str, t)
local str = apply_global_var(str, t)
if session then
str = apply_session_var(str, t)
end
return str
end
-- usage
-- apply_global_var('$${hold_music}')
--
-- dofile( apply_global_var('$${script_dir}/foo.lua') )
--
-- apply_global_var('$${storage_dir}/$${domain}',{
-- domain = 'my_domain';
-- })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.