<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Just returning a value from any random function won't have any effect. The return from hangup hook is special as thats a function we call from the c code. Its probably possible to add a method that you could run that would terminate the script, but I don't think there is any way to do that currently. On quick review, it looks like the way "exit" return from hangup hook is implemented is by way of calling <span style="color: rgb(191, 191, 191); font-family: Monaco; font-size: 13px; background-color: rgb(0, 0, 0);" class="">lua_error</span> from the c code, which would cause the script to terminate. Other than that, as was said above, the way to end a script is by way of returning from the body of it.<div class=""><br class=""><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 7, 2016, at 7:20 PM, Abaci B <<a href="mailto:abaci64@gmail.com" class="">abaci64@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">I just got around to test this again and here is what I found.</div><div class="">from within the hangup hook you can exit using <font face="monospace,monospace" class="">return "exit"</font> and as noted by Andrew it will exit with an error unless you set <font face="monospace,monospace" class="">debug.traceback=nil</font></div><div class="">from the main code (not within a function) you can exit by using <font face="monospace,monospace" class="">return "exit"</font> (or return anything else) which is just lua exiting but it has to be at the end of a block (wither a loop or you can just <font face="monospace,monospace" class="">return "exit" end</font>).</div><div class="">from within a function there seems to be no way to exit the lua script, for scripts that are session based you can probably use <font face="monospace,monospace" class="">session:hangup()</font> along with calling <font face="monospace,monospace" class="">return "exit"</font> from the hangup hook, but on any other lua scripts (api, event hooks, dialplan hook, startup) there seems to be no way.</div><div class="">So my question is if anyone know another way to exit a lua script from within a function or if I should open a Jira.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Mar 10, 2016 at 4:21 PM, Abaci B <span dir="ltr" class=""><<a href="mailto:abaci64@gmail.com" target="_blank" class="">abaci64@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="">I would expect to be able to exit from a lua script without a while loop, should I open a feature request on Jira for that?</div><div class=""><div class="h5"><div class=""><br class=""></div><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 9, 2016 at 1:20 AM, Chad Phillips <span dir="ltr" class=""><<a href="mailto:chad@apartmentlines.com" target="_blank" class="">chad@apartmentlines.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Andrew,<div class=""><br class=""></div><div class="">Curious if this structure will work at the bottom of either a a Lua script or Lua function:</div><div class=""><br class=""></div><div class="">do</div><div class=""> return "exit"</div><div class="">end</div><div class=""><br class=""></div><div class="">I seem to recall that being a trick that helped for weird 'return' cases.</div><span class=""><font color="#888888" class=""><div class=""><br class=""></div><div class="">Chad</div></font></span></div><div class="gmail_extra"><br class=""><div class="gmail_quote"><div class=""><div class="">On Tue, Mar 8, 2016 at 12:54 PM, Andrew Keil <span dir="ltr" class=""><<a href="mailto:andrew.keil@visytel.com" target="_blank" class="">andrew.keil@visytel.com</a>></span> wrote:<br class=""></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=""><div class="">
<div lang="EN-AU" vlink="purple" link="blue" class="">
<div class=""><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">Michael,<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">I have just run some more tests and you are correct that calling it inside a while loop like what you explained below does work outside of the hangup
hook handler. Thanks for providing this extra information.<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">It should be noted that it does not work on its own simply at the bottom of a Lua function (ie. as the last statement without a while loop) - except
as the last statement inside the hangup hook function.<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">ie. This works:<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">----------------------------------------------------------------<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">function CleanUp()<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> freeswitch.consoleLog("CLEANUP SECTION\n")<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n")<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">end<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">function myHangupHook(s, status, arg)<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> freeswitch.consoleLog(string.format("%s DETECTED\n",arg))<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> session:hangup()<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> -- Run CleanUp function now since the caller has disconnected
<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> CleanUp()<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> -- Abort Lua script here to avoid returning to MainService()<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> return "exit"
<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">end<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">-- Setup Hangup event handler here<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">v_hangup = "HANGUP"<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">session:setHangupHook("myHangupHook", "v_hangup")<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">Whereas this does not work:<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">----------------------------------------------------------------<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">function CleanUp()<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> freeswitch.consoleLog("CLEANUP SECTION\n")<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n")<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> return "exit"
<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">end
<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">function myHangupHook(s, status, arg)<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> freeswitch.consoleLog(string.format("%s DETECTED\n",arg))<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> session:hangup()<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> -- Run CleanUp function now since the caller has disconnected
<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> CleanUp()<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">end<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">-- Setup Hangup event handler here<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">v_hangup = "HANGUP"<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">session:setHangupHook("myHangupHook", "v_hangup")<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><a name="m_1710721875543731147_-1920980919_-766515437_1060642169__MailEndCompose" class=""><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">Regards,<u class=""></u><u class=""></u></span></a></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">Andrew<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><b class=""><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif" class=""> <a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank" class="">freeswitch-users-bounces@lists.freeswitch.org</a> [mailto:<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank" class="">freeswitch-users-bounces@lists.freeswitch.org</a>]
<b class="">On Behalf Of </b>Michael Collins<br class="">
<b class="">Sent:</b> Saturday, 5 March 2016 8:11 AM<br class="">
<b class="">To:</b> FreeSWITCH Users Help <<a href="mailto:freeswitch-users@lists.freeswitch.org" target="_blank" class="">freeswitch-users@lists.freeswitch.org</a>><br class="">
<b class="">Subject:</b> Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
<div class=""><p class="MsoNormal">On Fri, Mar 4, 2016 at 9:19 AM, Abaci B <<a href="mailto:abaci64@gmail.com" target="_blank" class="">abaci64@gmail.com</a>> wrote:<u class=""></u><u class=""></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm" class="">
<div class=""><p class="MsoNormal">The question is not how to figure out when to exit the lua script, the question is <b class="">how to exit the lua script</b>, and that can sometimes be tricky or complicated as return "exit" only works from hangup hook.<u class=""></u><u class=""></u></p>
</div>
</blockquote>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">Are you positive that it works only from a hangup hook? It seems to work at the end of any loop:<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class="">-- testing exit (no session, call with luarun)</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class="">freeswitch.consoleLog('INFO',"Starting infinite loop...\n")</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class="">while(1) do</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class=""> freeswitch.consoleLog('WARNING',"Before exit...\n")</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class=""> return "exit"</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class="">end</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class="">freeswitch.consoleLog('INFO',"All done!\n")</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">Or with a session:<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class="">-- test exit with session, no hangup hook</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class="">session:answer()</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class="">freeswitch.consoleLog('INFO',"Entering main loop...\n")</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class="">while ( session:ready() == true ) do</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class=""> freeswitch.consoleLog('WARNING',"Inside loop...\n")</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class=""> return "exit"</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class="">end</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><span style="font-family:"Courier New"" class="">freeswitch.consoleLog('INFO',"All done!\n")</span><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">In both cases I never see "All done!" at the CLI. Can you try it and see if there's a scenario where it does not exit as expected?<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">-MC<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"> <u class=""></u><u class=""></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
<br class=""></div></div><span class="">_________________________________________________________________________<br class="">
Professional FreeSWITCH Consulting Services:<br class="">
<a href="mailto:consulting@freeswitch.org" target="_blank" class="">consulting@freeswitch.org</a><br class="">
<a href="http://www.freeswitchsolutions.com/" target="_blank" rel="noreferrer" class="">http://www.freeswitchsolutions.com</a><br class="">
<br class="">
Official FreeSWITCH Sites<br class="">
<a href="http://www.freeswitch.org/" target="_blank" rel="noreferrer" class="">http://www.freeswitch.org</a><br class="">
<a href="http://confluence.freeswitch.org/" target="_blank" rel="noreferrer" class="">http://confluence.freeswitch.org</a><br class="">
<a href="http://www.cluecon.com/" target="_blank" rel="noreferrer" class="">http://www.cluecon.com</a><br class="">
<br class="">
FreeSWITCH-users mailing list<br class="">
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank" class="">FreeSWITCH-users@lists.freeswitch.org</a><br class="">
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank" rel="noreferrer" class="">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br class="">
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank" rel="noreferrer" class="">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br class="">
<a href="http://www.freeswitch.org/" target="_blank" rel="noreferrer" class="">http://www.freeswitch.org</a><br class=""></span></blockquote></div><br class=""></div>
<br class="">_________________________________________________________________________<br class="">
Professional FreeSWITCH Consulting Services:<br class="">
<a href="mailto:consulting@freeswitch.org" target="_blank" class="">consulting@freeswitch.org</a><br class="">
<a href="http://www.freeswitchsolutions.com/" target="_blank" rel="noreferrer" class="">http://www.freeswitchsolutions.com</a><br class="">
<br class="">
Official FreeSWITCH Sites<br class="">
<a href="http://www.freeswitch.org/" target="_blank" rel="noreferrer" class="">http://www.freeswitch.org</a><br class="">
<a href="http://confluence.freeswitch.org/" target="_blank" rel="noreferrer" class="">http://confluence.freeswitch.org</a><br class="">
<a href="http://www.cluecon.com/" target="_blank" rel="noreferrer" class="">http://www.cluecon.com</a><br class="">
<br class="">
FreeSWITCH-users mailing list<br class="">
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank" class="">FreeSWITCH-users@lists.freeswitch.org</a><br class="">
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank" rel="noreferrer" class="">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br class="">
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank" rel="noreferrer" class="">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br class="">
<a href="http://www.freeswitch.org/" target="_blank" rel="noreferrer" class="">http://www.freeswitch.org</a><br class=""></blockquote></div><br class=""></div></div></div></div>
</blockquote></div><br class=""></div>
_________________________________________________________________________<br class="">Professional FreeSWITCH Consulting Services: <br class=""><a href="mailto:consulting@freeswitch.org" class="">consulting@freeswitch.org</a><br class="">http://www.freeswitchsolutions.com<br class=""><br class="">Official FreeSWITCH Sites<br class="">http://www.freeswitch.org<br class="">http://confluence.freeswitch.org<br class="">http://www.cluecon.com<br class=""><br class="">FreeSWITCH-users mailing list<br class="">FreeSWITCH-users@lists.freeswitch.org<br class="">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users<br class="">UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users<br class="">http://www.freeswitch.org</div></blockquote></div><br class=""></div></div></body></html>