From bebf1d99a7a81ffd5cc3276acbf8b0317182a1af Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 29 Jan 2013 16:28:13 +0100 Subject: set variable function added --- misc/freeswitch/scripts/common/str.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'misc/freeswitch/scripts/common/str.lua') diff --git a/misc/freeswitch/scripts/common/str.lua b/misc/freeswitch/scripts/common/str.lua index 793c191..72ff388 100644 --- a/misc/freeswitch/scripts/common/str.lua +++ b/misc/freeswitch/scripts/common/str.lua @@ -18,6 +18,23 @@ function try(array, arguments) return result; end + +function set(array, arguments, value) + local nop, arguments_count = arguments:gsub('%.', ''); + local structure = array; + arguments:gsub('([^%.]+)', function(entry) + if arguments_count <= 0 then + structure[entry] = value; + elseif type(structure[entry]) == 'table' then + structure = structure[entry]; + else + structure[entry] = {}; + structure = structure[entry]; + end + arguments_count = arguments_count - 1; + end); +end + -- to number function to_n(value) value = tostring(value):gsub('[^%d%.%+%-]', ''); -- cgit v1.2.3