Installing LuaSocket
To install Luasocket on FreeSWITCH 1.4 (it uses Lua5.2, not compatible with luasocket 2.0.2), you need luasocket 3.0.rc1.
Download, unpack, modify, compile and install (edit LUAINC_linux dir to reflect your settings):
cd /usr/src
wget https://github.com/diegonehab/luasocket/archive/v3.0-rc1.zip
unzip v3.0-rc1.zip
cd luasocket-3.0-rc1/
cd src
perl -p -i.bak1 -e "s#luaL_openlib\(L, NULL, func, 0\)#luaL_register\(L, NULL, func\)#" *.c
perl -p -i.bak2 -e "s#luaL_openlib\(L, \"socket\", func, 0\)#luaL_register\(L, \"socket\", func\)#" *.c
perl -p -i.bak3 -e "s#luaL_openlib\(L, \"mime\", func, 0\)#luaL_register\(L, \"mime\", func\)#" *.c
cd ..
cd gem
perl -p -i.bak1 -e "s#luaL_openlib\(L, \"gem\", func, 0\)#luaL_register\(L, \"gem\", func\)#" *.c
cd ..
make PLAT=linux DEBUG=NODEBUG LUAV=5.2 prefix=/usr/local COMPAT=NOCOMPAT LUAINC_linux=/usr/src/freeswitch/src/mod/languages/mod_lua/lua
make PLAT=linux DEBUG=NODEBUG LUAV=5.2 prefix=/usr/local COMPAT=NOCOMPAT LUAINC_linux=/usr/src/freeswitch/src/mod/languages/mod_lua/lua install
for quick testing, put this in /usr/local/freeswitch/scripts/http.lua :
http = require "socket.http";
response_body, response_status_code, response_headers, response_status_line = http.request("http://www.example.com/");
stream:write("response_status_code = " .. response_status_code .. "\n");
stream:write("response_body = " .. response_body .. "\n");
for key,value in pairs(response_headers)
do
stream:write("response_headers = " .. key .. " => " .. value .. "\n") ;
end;
stream:write("response_status_line = " .. response_status_line .. "\n");
then enable mod_xml_rpc in FreeSWITCH (eg, from fs_cli: "load mod_xml_rpc") and access it at: [http://freeswitch:works@your.freeswitch.server.address:8080/api/lua?http.lua](http://freeswitch:works@your.freeswitch.server.address:8080/api/lua?http.lua)
(note freeswitch:works are default login and password to access mod_xml_rpc).