[Freeswitch-users] Call particular function in Lua script from console?
Tom C
mel0torme at gmail.com
Mon May 2 18:09:58 MSD 2011
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/abec70ba/attachment.html
More information about the FreeSWITCH-users
mailing list