diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-01-16 11:00:12 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-01-16 11:00:12 +0100 |
commit | 4194d7f689c3f70c9247e8006694cfcf667ebaf0 (patch) | |
tree | 671f056c3bb2d2fa4d88fdd61e00908daaa9ed79 /misc | |
parent | 22379d3a788c4d00cd12b738f01e5ca642b89ea4 (diff) | |
parent | 1de09183010a7f021455ce69877b78051d5c4bf1 (diff) |
Merge branch 'develop' of github.com:amooma/GS5 into develop
Diffstat (limited to 'misc')
-rw-r--r-- | misc/freeswitch/scripts/common/str.lua | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/misc/freeswitch/scripts/common/str.lua b/misc/freeswitch/scripts/common/str.lua index ca6dcd9..c366fda 100644 --- a/misc/freeswitch/scripts/common/str.lua +++ b/misc/freeswitch/scripts/common/str.lua @@ -5,23 +5,13 @@ 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 |