<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18828"></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=444521516-17112009><FONT color=#0000ff
size=2 face=Arial>MC,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=444521516-17112009><FONT color=#0000ff
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=444521516-17112009><FONT color=#0000ff
size=2 face=Arial>We would like the dialplan to route the call based on
Presence, which is a database lookup. I should be able to do this in Lua,
true?</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=444521516-17112009><FONT color=#0000ff
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=444521516-17112009><FONT color=#0000ff
size=2 face=Arial>Jerry</FONT></SPAN></DIV><BR>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px" dir=ltr>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B> Michael Collins
[mailto:msc@freeswitch.org] <BR><B>Sent:</B> Monday, November 16, 2009 11:33
AM<BR><B>To:</B> freeswitch-users@lists.freeswitch.org<BR><B>Subject:</B> Re:
[Freeswitch-users] Accessing Config Info From Database<BR></FONT><BR></DIV>
<DIV></DIV><BR><BR>
<DIV class=gmail_quote>On Mon, Nov 16, 2009 at 9:36 AM, Jerry Richards <SPAN
dir=ltr><<A
href="mailto:jerry.richards@teotech.com">jerry.richards@teotech.com</A>></SPAN>
wrote:<BR>
<BLOCKQUOTE
style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0pt 0pt 0pt 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote><BR>I have a bit of confusion about Lua scripting.
When a script is invoked,<BR>should it always return an XML string
that is used by FS? Or as in the case<BR>of dialplan examples, does it
actually execute the dialplan (e.g.<BR>"session:answer();")?<BR><BR>Best
Regards,<BR>Jerry<BR><BR></BLOCKQUOTE><BR>Jerry,<BR><BR>A Lua script that is
explicitly called from the dialplan will indeed execute dialplan-ish stuff.
For example, let's say you had this in conf/dialplan/default.xml:<BR><BR><SPAN
style="FONT-FAMILY: courier new,monospace"><extension name="lua
sample"></SPAN><BR style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace"> <condition
field="destination_number" expression="9876"></SPAN><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace"> <action
application="lua" data="/path/to/myluascript.lua"/></SPAN><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace"> </condition></SPAN><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace"></extension></SPAN><BR><BR>Then
myluascript.lua has something like:<BR><BR><SPAN
style="FONT-FAMILY: courier new,monospace">--Sample Lua script</SPAN><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace">session:answer()</SPAN><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace">session:sleep(1000)</SPAN><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace">session:streamFile("/path/to/file.wav")</SPAN><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace">session:hangup()</SPAN><BR
style="FONT-FAMILY: courier new,monospace"><BR>Assuming an otherwise default
install, the above Lua script would execute when a caller dialed 9876, or if a
call was x-ferred to 9876.<BR><BR>However, if you're wanting to use Lua to
serve up a dialplan then it's totally different. Lua is not called from the
dialplan; Lua provides the dialplan to FreeSWITCH. This latter case is the
scenario discussed in the wiki section you referenced. (<A
href="http://wiki.freeswitch.org/wiki/Lua#For_serving_configuration">http://wiki.freeswitch.org/wiki/Lua#For_serving_configuration</A>)<BR><BR>Are
you trying to use Lua scripting for serving up a dynamic configuration of some
sort?<BR>-MC<BR><BR><BR></DIV></BLOCKQUOTE></BODY></HTML>