About

We will explain here how you can use luarocks to install third party libraries and use them in your Lua application

 

Luarocks

Luarocks is a package/library manager for lua. It can install libraries into a systemwide directory and then you can Freeswitch's LUA to use them. You may have to install a systemwide lua just to keep the luarocks installer happy...

For example if you want the LuaXML library in Ubuntu 12.04:

sudo apt-get install lua5.2 luarocks
luarocks install luaxml

Then edit /usr/local/freeswitch/conf/autoload_configs/lua.conf.xml, de-comment lines to leave the following:

<param name="module-directory" value="/usr/lib/lua/5.2/?.so"/>
<param name="module-directory" value="/usr/local/lib/lua/5.2/?.so"/>

You may also add it manually in a script:

package.path = package.path .. ";" .. [[/usr/share/lua/5.2/?.lua]]

 

A lua script in your dialplan can now use the XML functions. A trivial example:

require("LuaXml")
local xobj = xml.eval('<Cmd Message="Hello"/>')
freeswitch.consoleLog("INFO","The message in the XML is "..xobj["Message"].."\n")

Where to put third party Lua scripts/modules

Where do I need to stick my Lua classes for FreeSWITCH to see them. I am running a Lua script from within the /scripts folder, but it includes (requires) another Lua file. FreeSWITCH.

The short answer is /usr/local/share/lua/5.1/

Alternatively, you can install a system Lua (think apt-get or yum), and the Lua embedded in freeswitch will look in the add-ons directory.

To do this in the mod_lua.conf file (currently not possible), the following development would be needed.

* Install them to a nonstandard.
* Push a nonstandard place into the path of where it looks.

NOTE: Assuming you have <param name="module-directory" value="$${base_dir}/scripts/?.so"/> in lua.conf.xml, in the scripts, require statements in the form of:

require "luasql.mysql"

This will look for the shared object ${base_dir}/scripts/luasql/mysql.so

NOTE: The native MySQL driver for Lua has a very bad memory leak. Do not use it.