From 473e6c52eff0576829138b59b99f83917ff6b0e9 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 16 Jan 2013 10:31:01 +0100 Subject: faster try function --- misc/freeswitch/scripts/common/str.lua | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (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 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 -- cgit v1.2.3 From 8744de13516c3fc2fbf2843e85aff08707f50de1 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Fri, 18 Jan 2013 12:54:45 +0100 Subject: adjust copyright date for 2013 --- misc/freeswitch/scripts/common/str.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 c366fda..32f054e 100644 --- a/misc/freeswitch/scripts/common/str.lua +++ b/misc/freeswitch/scripts/common/str.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: string functions --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) -- cgit v1.2.3