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:
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@internal> global_setvar myparameter=My Contents
freeswitch@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