Gerald,<br><br>This is a feature/quirk of Lua. There is no explicit exit command. The script keeps running until there are no more commands. You&#39;ll need to restructure your loops so that when someone hangups it breaks out of the outermost loop and then has nothing left to execute.<br>
<br>-MC<br><br><div class="gmail_quote">On Wed, Jan 25, 2012 at 3:17 AM, Gerald Weber <span dir="ltr">&lt;<a href="mailto:gerald.weber@besharp.at">gerald.weber@besharp.at</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="blue" vlink="purple" lang="DE-AT"><div><p class="MsoNormal"><span lang="EN-US">Hello,<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">i’m trying to exit my lua script (called from dialplan) to exit in the the hanguphook:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">function on_hangup(s,status)<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">        freeswitch.consoleLog(&quot;NOTICE&quot;,&quot;---- on_hangup: &quot;..status..&quot;\n&quot;);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">        error(); <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">end<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal">
<span lang="EN-US">freeswitch.consoleLog(&quot;NOTICE&quot;,&quot;---- ANSWER:\n&quot;);<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">session:answer();<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">freeswitch.consoleLog(&quot;NOTICE&quot;,&quot;---- SETHOOK: \n&quot;);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">session:setHangupHook(&quot;on_hangup&quot;);<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">while (session:ready() == true) do<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">        freeswitch.consoleLog(&quot;NOTICE&quot;,&quot;---- START OF LOOP \n&quot;);<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">        freeswitch.consoleLog(&quot;NOTICE&quot;,&quot;---- STREAMFILE \n&quot;);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">        session:streamFile(&quot;/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-on_hold_indefinitely.wav&quot;);<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">        freeswitch.consoleLog(&quot;NOTICE&quot;,&quot;---- END OF SCRIPT 1 -&gt; HANGUP\n&quot;);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">end<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">freeswitch.consoleLog(&quot;NOTICE&quot;,&quot;---- END OF SCRIPT 2 -&gt; HANGUP\n&quot;);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">session:hangup()<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">When I hangup during the  streamFile Call, I geht the following output:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:19.936097 [NOTICE] switch_channel.c:930 New Channel sofia/internal/<a href="mailto:2001@192.168.20.73" target="_blank">2001@192.168.20.73</a> [2b1cd9f6-4745-11e1-8c71-0d2938abf0b5]<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:19.936097 [INFO] mod_dialplan_xml.c:481 Processing B#-FS-2001 &lt;2001&gt;-&gt;3001 in context default<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- ANSWER:<u></u><u></u></span></p><p class="MsoNormal">
<span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:19.936097 [NOTICE] switch_cpp.cpp:599 Channel [sofia/internal/<a href="mailto:2001@192.168.20.73" target="_blank">2001@192.168.20.73</a>] has been answered<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- SETHOOK:<u></u><u></u></span></p><p class="MsoNormal">
<span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- START OF LOOP<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- STREAMFILE<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:21.116050 [NOTICE] sofia.c:624 Hangup sofia/internal/<a href="mailto:2001@192.168.20.73" target="_blank">2001@192.168.20.73</a> [CS_EXECUTE] [NORMAL_CLEARING]<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- on_hangup: hangup<u></u><u></u></span></p><p class="MsoNormal">
<span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- END OF SCRIPT 1 -&gt; HANGUP<u></u><u></u></span></p><p class="MsoNormal">
<span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- END OF SCRIPT 2 -&gt; HANGUP<u></u><u></u></span></p><p class="MsoNormal">
<span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:21.116050 [NOTICE] switch_core_session.c:1398 Session 2 (sofia/internal/<a href="mailto:2001@192.168.20.73" target="_blank">2001@192.168.20.73</a>) Ended<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:10:21.116050 [NOTICE] switch_core_session.c:1400 Close Channel sofia/internal/<a href="mailto:2001@192.168.20.73" target="_blank">2001@192.168.20.73</a> [CS_DESTROY]<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">Why does the hangup handler return and the rest of the script is executed ?<u></u><u></u></span></p><p class="MsoNormal">
<span lang="EN-US">I event tried “do return end;” , “exit;” ,” exit();” instead of “error(); - none of them works.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal">
<span lang="EN-US">If i put the same logic into javascript, the hook works and the script is terminated:<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">function on_hangup(s,status)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">{<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">        console_log(&quot;NOTICE&quot;,&quot;---- hangup &quot;+status+&quot;\n&quot;);<u></u><u></u></span></p><p class="MsoNormal">
<span lang="EN-US">        return &quot;exit&quot;;<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">}<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal">
<span lang="EN-US">console_log(&quot;NOTICE&quot;,&quot;---- ANSWER\n&quot;);<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">session.answer();<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">console_log(&quot;NOTICE&quot;,&quot;---- ANSWER\n&quot;);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">session.setHangupHook(on_hangup);<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">while(session.ready())<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">{<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">        console_log(&quot;NOTICE&quot;,&quot;---- START OF LOOP\n&quot;);<u></u><u></u></span></p><p class="MsoNormal">
<span lang="EN-US">        session.streamFile(&quot;/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-on_hold_indefinitely.wav&quot;);<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">        console_log(&quot;NOTICE&quot;,&quot;---- END OF LOOP\n&quot;);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">}<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">console_log(&quot;NOTICE&quot;,&quot;---- END OF SCRIPT\n&quot;);<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">session.hangup();<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:13:08.396041 [NOTICE] switch_channel.c:930 New Channel sofia/internal/<a href="mailto:2001@192.168.20.73" target="_blank">2001@192.168.20.73</a> [8f85a15c-4745-11e1-8c76-0d2938abf0b5]<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:13:08.396041 [INFO] mod_dialplan_xml.c:481 Processing B#-FS-2001 &lt;2001&gt;-&gt;3002 in context default<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:13:08.396041 [NOTICE] hangup.js:1 ---- ANSWER<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:13:08.396041 [NOTICE] mod_spidermonkey.c:2068 Channel [sofia/internal/<a href="mailto:2001@192.168.20.73" target="_blank">2001@192.168.20.73</a>] has been answered<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:13:08.396041 [NOTICE] hangup.js:1 ---- ANSWER<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:13:08.396041 [NOTICE] hangup.js:1 ---- START OF LOOP<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:13:09.875996 [NOTICE] sofia.c:624 Hangup sofia/internal/<a href="mailto:2001@192.168.20.73" target="_blank">2001@192.168.20.73</a> [CS_EXECUTE] [NORMAL_CLEARING]<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:13:09.875996 [NOTICE] hangup.js:2 ---- hangup hangup<u></u><u></u></span></p><p class="MsoNormal">
<span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:13:09.875996 [NOTICE] switch_core_session.c:1398 Session 3 (sofia/internal/<a href="mailto:2001@192.168.20.73" target="_blank">2001@192.168.20.73</a>) Ended<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="tel:2012-01-25%2012" value="+12012012512" target="_blank">2012-01-25 12</a>:13:09.875996 [NOTICE] switch_core_session.c:1400 Close Channel sofia/internal/<a href="mailto:2001@192.168.20.73" target="_blank">2001@192.168.20.73</a> [CS_DESTROY]<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">Any suggestions ? Or do i miss something here ?<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">The dialplan part:<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal">
<span lang="EN-US">    &lt;extension name=&quot;hanguptest&quot;&gt;<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">     &lt;condition field=&quot;destination_number&quot; expression=&quot;^(3001)$&quot;&gt;<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">        &lt;action application=&quot;set&quot; data=&quot;session_in_hangup_hook=true&quot;/&gt;<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">       &lt;action application=&quot;lua&quot; data=&quot;hangup.lua&quot;/&gt;<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">     &lt;/condition&gt;<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">    &lt;/extension&gt;<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">(replace hangup.lua with hangup.js for the javascript version)<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">Freeswitch Version:<u></u><u></u></span></p><p class="MsoNormal">
<span lang="EN-US">FreeSWITCH Version 1.0.head (git-9be51d5 2012-01-21 13-45-21 -0500)<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal">thx&amp;regards,<u></u><u></u></p>
<p class="MsoNormal">gw<u></u><u></u></p></div></div><br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br>