[Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function
Chad Phillips
chad at apartmentlines.com
Wed Mar 9 09:20:17 MSK 2016
Andrew,
Curious if this structure will work at the bottom of either a a Lua script
or Lua function:
do
return "exit"
end
I seem to recall that being a trick that helped for weird 'return' cases.
Chad
On Tue, Mar 8, 2016 at 12:54 PM, Andrew Keil <andrew.keil at visytel.com>
wrote:
> Michael,
>
>
>
> 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.
>
>
>
> 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.
>
>
>
> ie. This works:
>
> ----------------------------------------------------------------
>
>
>
>
>
> function CleanUp()
>
> freeswitch.consoleLog("CLEANUP SECTION\n")
>
> freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n")
>
> end
>
>
>
> function myHangupHook(s, status, arg)
>
> freeswitch.consoleLog(string.format("%s DETECTED\n",arg))
>
> session:hangup()
>
> -- Run CleanUp function now since the caller has
> disconnected
>
> CleanUp()
>
> -- Abort Lua script here to avoid returning to
> MainService()
>
> return "exit"
>
> end
>
> -- Setup Hangup event handler here
>
> v_hangup = "HANGUP"
>
> session:setHangupHook("myHangupHook", "v_hangup")
>
>
>
> Whereas this does not work:
>
> ----------------------------------------------------------------
>
>
>
> function CleanUp()
>
> freeswitch.consoleLog("CLEANUP SECTION\n")
>
> freeswitch.consoleLog("CLEANUP SECTION COMPLETE\n")
>
> return "exit"
>
> end
>
>
>
> function myHangupHook(s, status, arg)
>
> freeswitch.consoleLog(string.format("%s DETECTED\n",arg))
>
> session:hangup()
>
> -- Run CleanUp function now since the caller has
> disconnected
>
> CleanUp()
>
> end
>
> -- Setup Hangup event handler here
>
> v_hangup = "HANGUP"
>
> session:setHangupHook("myHangupHook", "v_hangup")
>
>
>
> Regards,
>
>
>
> Andrew
>
>
>
> *From:* freeswitch-users-bounces at lists.freeswitch.org [mailto:
> freeswitch-users-bounces at lists.freeswitch.org] *On Behalf Of *Michael
> Collins
> *Sent:* Saturday, 5 March 2016 8:11 AM
> *To:* FreeSWITCH Users Help <freeswitch-users at lists.freeswitch.org>
> *Subject:* Re: [Freeswitch-users] Re- End Lua script after HangupHook
> handled without all the extra code to handle the return to the function
>
>
>
>
>
>
>
> On Fri, Mar 4, 2016 at 9:19 AM, Abaci B <abaci64 at gmail.com> wrote:
>
> The question is not how to figure out when to exit the lua script, the
> question is *how to exit the lua script*, and that can sometimes be
> tricky or complicated as return "exit" only works from hangup hook.
>
>
>
> Are you positive that it works only from a hangup hook? It seems to work
> at the end of any loop:
>
>
>
> -- testing exit (no session, call with luarun)
>
> freeswitch.consoleLog('INFO',"Starting infinite loop...\n")
>
> while(1) do
>
> freeswitch.consoleLog('WARNING',"Before exit...\n")
>
> return "exit"
>
> end
>
> freeswitch.consoleLog('INFO',"All done!\n")
>
>
>
>
>
> Or with a session:
>
> -- test exit with session, no hangup hook
>
> session:answer()
>
> freeswitch.consoleLog('INFO',"Entering main loop...\n")
>
> while ( session:ready() == true ) do
>
> freeswitch.consoleLog('WARNING',"Inside loop...\n")
>
> return "exit"
>
> end
>
> freeswitch.consoleLog('INFO',"All done!\n")
>
>
>
> 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?
>
>
>
> -MC
>
>
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://confluence.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20160308/e00369a4/attachment.html
Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users
mailing list