Lua and FreeSWITCH
Calling a Lua script from FreeSWITCH makes one object available: the "freeswitch" object (from which you can create other basic FreeSWITCH-related objects).
You can execute a Lua script from FreeSWITCH console in two ways: lua
and luarun
. If you execute the script with lua
, it will block your console until the script returns, as though it was the console thread itself to execute the script. Only after the script has exited will you see console messages. If instead you use luarun
, a new thread will be created that will run the script (in this case the script will have no access to the stream
object) completely independently from the console.
If the Lua script has been called from dialplan (an incoming call matches an extension where a lua
action is executed), then an additional object is automatically already available: session
. The object session
represents the call leg and lets you interact with it (answer, play media, get DTMFs, hangup, and so on).
Let's play a little with...