Hi All, I have modified this excellent example LUA script (https://confluence.freeswitch.org/display/FREESWITCH/Lua+Intercom+example) to return "true" if an extension is in use and "false" otherwise". Just FYI: this is great for Cisco phones because an auto-answer (intercom) connection will interrupt the current call unless you block ALL intercom use. With this I can sent intercom if not in use, or send as a standard call otherwise. My complements to the original chef! My request is for someone to explain the pattern matching pattern used in this function: function trim (s) return (string.gsub(s, "^%s*(.-)%s*$", "%1")) end It takes a string like this: "uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,application,application_data,dialplan,context,read_codec,read_rate,read_bit_rate,write_codec,write_rate,write_bit_rate,secure,hostname,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid,sent_callee_name,sent_callee_num d7bd917c-efca-4333-81f6-692c727069a2,inbound,2014-07-18 11:59:41,1405699181,sofia/external_noauth/4107673000@66.241.96.237,CS_EXECUTE,+14107673000,4107673000,66.241.96.237,BOOKKEEPING,voicemail,default voicemail_ESTA 40,XML,from-internal-ESTA,L16,8000,128000,PCMU,8000,64000,,fs_bfis.bizfocused.com,4107673000@66.241.96.237,,ACTIVE,,,,,, 1 total." or just this: " 0 total." And returns just the number and the "Total." at the end, like "1 total." Or "0 total." I am fairly regex pattern savvy so I understand pattern matching, but I cannot decipher this LUA pattern. I see it works, but I would like to understand how/why. Thanks as always, Sean
From my experience with lua its treating %s as any whitespace, starts with any number of spaces, then it says anything after the spaces non greedy, then followed by a string, ending with that string More info here: http://lua-users.org/wiki/PatternsTutorial On Fri, Jul 18, 2014 at 10:10 AM, Sean Devoy <sdevoy@bizfocused.com> wrote:
Hi All,
I have modified this excellent example LUA script ( https://confluence.freeswitch.org/display/FREESWITCH/Lua+Intercom+example) to return “true” if an extension is in use and “false” otherwise”. Just FYI: this is great for Cisco phones because an auto-answer (intercom) connection will interrupt the current call unless you block ALL intercom use. With this I can sent intercom if not in use, or send as a standard call otherwise. My complements to the original chef!
My request is for someone to explain the pattern matching pattern used in this function:
function trim (s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
It takes a string like this:
“uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,application,application_data,dialplan,context,read_codec,read_rate,read_bit_rate,write_codec,write_rate,write_bit_rate,secure,hostname,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid,sent_callee_name,sent_callee_num
d7bd917c-efca-4333-81f6-692c727069a2,inbound,2014-07-18 11:59:41,1405699181,sofia/external_noauth/4107673000@66.241.96.237,CS_EXECUTE,+14107673000,4107673000,66.241.96.237,BOOKKEEPING,voicemail,default voicemail_ESTA 40,XML,from-internal-ESTA,L16,8000,128000,PCMU,8000,64000,, fs_bfis.bizfocused.com,4107673000@66.241.96.237,,ACTIVE,,,,,,
1 total.”
or just this:
“
0 total.”
And returns just the number and the “Total.” at the end, like “1 total.” Or “0 total.”
I am fairly regex pattern savvy so I understand pattern matching, but I cannot decipher this LUA pattern. I see it works, but I would like to understand how/why.
Thanks as always,
Sean
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
err, followed by space(s) ending with spaces* sorry was typing faster than i was thinking. On Fri, Jul 18, 2014 at 10:17 AM, Chris Tunbridge <blasterjr@gmail.com> wrote:
From my experience with lua its treating %s as any whitespace, starts with any number of spaces, then it says anything after the spaces non greedy, then followed by a string, ending with that string
More info here: http://lua-users.org/wiki/PatternsTutorial
On Fri, Jul 18, 2014 at 10:10 AM, Sean Devoy <sdevoy@bizfocused.com> wrote:
Hi All,
I have modified this excellent example LUA script ( https://confluence.freeswitch.org/display/FREESWITCH/Lua+Intercom+example) to return “true” if an extension is in use and “false” otherwise”. Just FYI: this is great for Cisco phones because an auto-answer (intercom) connection will interrupt the current call unless you block ALL intercom use. With this I can sent intercom if not in use, or send as a standard call otherwise. My complements to the original chef!
My request is for someone to explain the pattern matching pattern used in this function:
function trim (s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
It takes a string like this:
“uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,application,application_data,dialplan,context,read_codec,read_rate,read_bit_rate,write_codec,write_rate,write_bit_rate,secure,hostname,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid,sent_callee_name,sent_callee_num
d7bd917c-efca-4333-81f6-692c727069a2,inbound,2014-07-18 11:59:41,1405699181,sofia/external_noauth/4107673000@66.241.96.237 ,CS_EXECUTE,+14107673000,4107673000,66.241.96.237,BOOKKEEPING,voicemail,default voicemail_ESTA 40,XML,from-internal-ESTA,L16,8000,128000,PCMU,8000,64000,, fs_bfis.bizfocused.com,4107673000@66.241.96.237,,ACTIVE,,,,,,
1 total.”
or just this:
“
0 total.”
And returns just the number and the “Total.” at the end, like “1 total.” Or “0 total.”
I am fairly regex pattern savvy so I understand pattern matching, but I cannot decipher this LUA pattern. I see it works, but I would like to understand how/why.
Thanks as always,
Sean
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
"^%s*(.-)%s*$", "%1" Lua uses it's own regex syntax, which is different from others you might be used to (eg PCRE). Though there's a few similarities. Match start of line, 0+ space, 0+ any character (as few times as possible, so it doesn't include any trailing spaces), 0+ space, end of string When matched replace the string with the matched portion. It'll match any string. It replaces it with the middle portion that excludes the leading/trailing spaces. In this case I assume ^$ are matching the start/end of lines not strings, and matching just the final line so you're only left with the '0 Total' On 18 July 2014 17:10, Sean Devoy <sdevoy@bizfocused.com> wrote:
Hi All,
I have modified this excellent example LUA script ( https://confluence.freeswitch.org/display/FREESWITCH/Lua+Intercom+example) to return “true” if an extension is in use and “false” otherwise”. Just FYI: this is great for Cisco phones because an auto-answer (intercom) connection will interrupt the current call unless you block ALL intercom use. With this I can sent intercom if not in use, or send as a standard call otherwise. My complements to the original chef!
My request is for someone to explain the pattern matching pattern used in this function:
function trim (s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
It takes a string like this:
“uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,application,application_data,dialplan,context,read_codec,read_rate,read_bit_rate,write_codec,write_rate,write_bit_rate,secure,hostname,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid,sent_callee_name,sent_callee_num
d7bd917c-efca-4333-81f6-692c727069a2,inbound,2014-07-18 11:59:41,1405699181,sofia/external_noauth/4107673000@66.241.96.237,CS_EXECUTE,+14107673000,4107673000,66.241.96.237,BOOKKEEPING,voicemail,default voicemail_ESTA 40,XML,from-internal-ESTA,L16,8000,128000,PCMU,8000,64000,, fs_bfis.bizfocused.com,4107673000@66.241.96.237,,ACTIVE,,,,,,
1 total.”
or just this:
“
0 total.”
And returns just the number and the “Total.” at the end, like “1 total.” Or “0 total.”
I am fairly regex pattern savvy so I understand pattern matching, but I cannot decipher this LUA pattern. I see it works, but I would like to understand how/why.
Thanks as always,
Sean
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
participants (3)
-
Chris Tunbridge
-
Sean Devoy
-
Steven Ayre