Wednesday, September 29, 2010

Best of New in Kamailio 3.1.0 - #2: Embedded Lua

Lua is a small, fast and easy to embed programming language ( It is a good choice to implement the routing logic for complex requirements in a SIP Server.

A new module in 3.1.0, named app_lua, provides the functionality to execute Lua code and scripts in your configuration file.

The readme and the API are available at:

Lua language is small and fast, therefore fits very well in a sip proxy environment, it has a lot of extensions, so when you cannot do something with existing cfg functions, check Lua documentation. The interpreter is embedded in app_lua module, so it is executed within Kamailio context.

Inside the Lua scripts, you get access to SIP message and functions from Kamailio core and modules. I did a presentation at Amoocon 2010 showing a practical example: how to use Lua to send notifications to Twitter from your SIP server, see the slides at:
Here is an example of sending a SIP reply through Lua:
lua_dostring(", [[Lua says is ok]])");
This is execution of Lua code provided within the string parameter of lua_dostring(). Also, you can execute a Lua script by providing the path in the parameter of lua_dofile():
Other options to run Lua code are provide by the new module, like to load a script at startup and execute functions from it at runtime.

No comments:

Post a Comment