<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 4, 2016 at 9:19 AM, Abaci B <span dir="ltr">&lt;<a href="mailto:abaci64@gmail.com" target="_blank">abaci64@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">The question is not how to figure out when to exit the lua script, the question is <b>how to exit the lua script</b>, and that can sometimes be tricky or complicated as return &quot;exit&quot; only works from hangup hook.</div></blockquote><div><br></div><div>Are you positive that it works only from a hangup hook? It seems to work at the end of any loop:</div><div><br></div><div><font face="monospace, monospace">-- testing exit (no session, call with luarun)</font></div><div><font face="monospace, monospace">freeswitch.consoleLog(&#39;INFO&#39;,&quot;Starting infinite loop...\n&quot;)</font></div><div><font face="monospace, monospace">while(1) do</font></div><div><font face="monospace, monospace">  freeswitch.consoleLog(&#39;WARNING&#39;,&quot;Before exit...\n&quot;)</font></div><div><font face="monospace, monospace">  return &quot;exit&quot;</font></div><div><font face="monospace, monospace">end</font></div><div><font face="monospace, monospace">freeswitch.consoleLog(&#39;INFO&#39;,&quot;All done!\n&quot;)</font></div><div><br></div><div><br></div><div>Or with a session:</div><div><font face="monospace, monospace">-- test exit with session, no hangup hook</font></div><div><font face="monospace, monospace">session:answer()</font></div><div><font face="monospace, monospace">freeswitch.consoleLog(&#39;INFO&#39;,&quot;Entering main loop...\n&quot;)</font></div><div><font face="monospace, monospace">while ( session:ready() == true ) do</font></div><div><font face="monospace, monospace">  freeswitch.consoleLog(&#39;WARNING&#39;,&quot;Inside loop...\n&quot;)</font></div><div><font face="monospace, monospace">  return &quot;exit&quot;</font></div><div><font face="monospace, monospace">end</font></div><div><font face="monospace, monospace">freeswitch.consoleLog(&#39;INFO&#39;,&quot;All done!\n&quot;)</font></div><div><br></div><div>In both cases I never see &quot;All done!&quot; at the CLI. Can you try it and see if there&#39;s a scenario where it does not exit as expected?</div><div><br></div><div>-MC</div><div> </div></div></div></div>