<div>That's exactly what I need. Thank you!!!!</div>
<div><br><br> </div>
<div class="gmail_quote">On Mon, May 2, 2011 at 8:03 AM, Grmt <span dir="ltr"><<a href="mailto:garmt.noname@gmail.com">garmt.noname@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div lang="EN-US" vlink="purple" link="blue">
<div>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">Why not use command line arguments and parse them in your lua script with argv[x] (where x is 0,1,2 …)?</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">e.g.</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">lua call_report.lua yesterday</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">-- call_report.lua</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">print(“enter a number”)</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">a = io.read(“*number”)</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">if argv[1] == “yesterday” then</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> print(“Sorry we were closed, it was Sunday\n”)</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">else</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> print(“calls today: \n” .. a * 12345) -- we like to show our boss that is was really busy</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">end</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">I suggest you start reading here:</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"><a href="http://www.lua.org/pil/1.html" target="_blank">http://www.lua.org/pil/1.html</a> (lua getting started ...)</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">Note: If you want users to interact with freeswitch I recommend doing that from outside fs and connect to fs with esl (and you could still use lua for that).</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">Grmt</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<div style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<p class="MsoNormal"><b><span style="FONT-SIZE: 10pt">From:</span></b><span style="FONT-SIZE: 10pt"> <a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a> [mailto:<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a>] <b>On Behalf Of </b>Tom C<br>
<b>Sent:</b> Monday, 02 May, 2011 16:10<br><b>To:</b> FreeSWITCH Users Help<br><b>Subject:</b> [Freeswitch-users] Call particular function in Lua script from console?</span></p></div>
<div>
<div></div>
<div class="h5">
<p class="MsoNormal"> </p>
<div>
<p class="MsoNormal">Hi! Is there any way to pass parameters to a Lua script, or to call a particular function within a lua script, when calling it with the "lua" command from the console? (I can accomplish what I need using global_setvar, but that's an extra step for the user.)</p>
</div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">I'm looking for something more like this:</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal"> <a href="mailto:freeswitch@internal" target="_blank">freeswitch@internal</a>> lua MyFunction("myContents") in MyLuaScriptFile.lua</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">Alternatively, is there a way to get input from the console, or otherwise interact with the user? Such as:</p></div>
<div>
<p class="MsoNormal"> stream:write("Enter user name:")</p></div>
<div>
<p class="MsoNormal"> cUserName = stream:readln() -- :-)</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">For anyone who is curious, the global_setvar method of passing info to a script can be done like this...</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">In the console, set the global variable(s), then call the script:</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal"> freeswitch@internal> global_setvar myparameter=My Contents</p></div>
<div>
<p class="MsoNormal"> freeswitch@internal> lua MyLuaScriptFile.lua</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">(Note that there were no quotes around the string.) And in the script:</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal"> fsapi = freeswitch.API();</p></div>
<div>
<p class="MsoNormal"> myParameter = fsapi:execute("global_getvar", "myparameter")</p></div>
<div>
<p class="MsoNormal"> if string.len(myParameter) == 0 then</p></div>
<div>
<p class="MsoNormal"> -- Global variable does not exist or is empty!</p></div>
<div>
<p class="MsoNormal"> stream:write('ERROR: Please use "global_setvar myparameter=My Contents'"to specify user.\n')</p></div>
<div>
<p class="MsoNormal"> return false</p></div>
<div>
<p class="MsoNormal"> else</p></div>
<div>
<p class="MsoNormal"> -- We retrieved contents of global. </p></div>
<div>
<p class="MsoNormal"> -- Might want to clean out the global to avoid later confusion.</p></div>
<div>
<p class="MsoNormal"> fsapi.:execute("global_setvar", "myparameter=")</p></div>
<div>
<p class="MsoNormal"> end</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal"> </p></div></div></div></div></div><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>