[Freeswitch-users] Call particular function in Lua script from console?

Grmt garmt.noname at gmail.com
Mon May 2 19:03:17 MSD 2011


Why not use command line arguments and parse them in your lua script with
argv[x] (where x is 0,1,2 .)?

e.g.

lua call_report.lua yesterday

 

-- call_report.lua

print("enter a number")

a = io.read("*number")

 

if argv[1] == "yesterday" then

                print("Sorry we were closed, it was Sunday\n")

else

                print("calls today: \n" .. a * 12345)  -- we like to show
our boss that is was really busy

end

 

I suggest you start reading here:

http://www.lua.org/pil/1.html (lua getting started ...)

 

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).

 

Grmt

 

From: freeswitch-users-bounces at lists.freeswitch.org
[mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Tom C
Sent: Monday, 02 May, 2011 16:10
To: FreeSWITCH Users Help
Subject: [Freeswitch-users] Call particular function in Lua script from
console?

 

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.)

 

I'm looking for something more like this:

 

    freeswitch at internal> lua MyFunction("myContents") in MyLuaScriptFile.lua

 

Alternatively, is there a way to get input from the console, or otherwise
interact with the user?  Such as:

  stream:write("Enter user name:")

  cUserName = stream:readln()     --  :-)

 

 

For anyone who is curious, the global_setvar method of passing info to a
script can be done like this...

 

In the console, set the global variable(s), then call the script:

 

   freeswitch at internal> global_setvar myparameter=My Contents

   freeswitch at internal> lua MyLuaScriptFile.lua

 

(Note that there were no quotes around the string.)  And in the script:

 

   fsapi = freeswitch.API();

   myParameter = fsapi:execute("global_getvar", "myparameter")

   if string.len(myParameter) == 0 then

       -- Global variable does not exist or is empty!

       stream:write('ERROR: Please use "global_setvar myparameter=My
Contents'"to specify user.\n')

       return false

   else

       -- We retrieved contents of global.  

       -- Might want to clean out the global to avoid later confusion.

       fsapi.:execute("global_setvar", "myparameter=")

   end

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20110502/325682ff/attachment-0001.html 


More information about the FreeSWITCH-users mailing list