summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/common/str.lua
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-22 15:33:06 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-22 15:33:06 +0100
commit39aa7132ceed3d4beab3a9b828e571bbfc67c07e (patch)
tree6c88289c9f99be0af8635636fcdf64102090e5ec /misc/freeswitch/scripts/common/str.lua
parent5ad8203ce4f1bfea997960d0b52c626dea24b944 (diff)
parent6f69c1a85055ec7c2515719d79d2a7a4e60cec50 (diff)
Merge branch 'develop'5.1-beta1
Diffstat (limited to 'misc/freeswitch/scripts/common/str.lua')
-rw-r--r--misc/freeswitch/scripts/common/str.lua24
1 files changed, 7 insertions, 17 deletions
diff --git a/misc/freeswitch/scripts/common/str.lua b/misc/freeswitch/scripts/common/str.lua
index ca6dcd9..32f054e 100644
--- a/misc/freeswitch/scripts/common/str.lua
+++ b/misc/freeswitch/scripts/common/str.lua
@@ -1,27 +1,17 @@
-- Gemeinschaft 5 module: string functions
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
function try(array, arguments)
- local argument = arguments:match('^(.-)%.') or arguments;
- local remaining_arguments = arguments:match('%.(.-)$');
- argument = tonumber(argument) or argument;
+ local result = array;
- if argument and type(array) == 'table' then
- if remaining_arguments then
- if type(array[argument]) == 'table' then
- return try(array[argument], remaining_arguments);
- else
- return nil;
- end
- else
- return array[argument];
- end
- end
-
- return nil;
+ arguments:gsub('([^%.]+)', function(entry)
+ local success, result = pcall(function() result = (result[tonumber(entry) or entry]); end);
+ end);
+
+ return result;
end
-- to number