diff --git a/src/modules/app_lua/Makefile b/src/modules/app_lua/Makefile index 0b630e6f76d..567b2e8b886 100644 --- a/src/modules/app_lua/Makefile +++ b/src/modules/app_lua/Makefile @@ -5,92 +5,104 @@ include ../../Makefile.defs auto_gen= NAME=app_lua.so -ifeq ($(CROSS_COMPILE),) - BUILDER = $(shell which lua-config) -endif - -ifeq ($(BUILDER),) +ifeq ($(LUAJIT),) ifeq ($(CROSS_COMPILE),) - BUILDER = $(shell which pkg-config) + BUILDER = $(shell which lua-config) endif + ifeq ($(BUILDER),) - LUA51 = $(shell ls $(LOCALBASE)/lib/liblua* | grep liblua5.1) - DEFS+= -I$(LOCALBASE)/include - LIBS+= -L$(LOCALBASE)/lib -lm - ifneq ($(LUA51),) - DEFS+= -I$(LOCALBASE)/include/lua5.1 - LIBS+= -llua5.1 - else - LUA52 = $(shell ls $(LOCALBASE)/lib/liblua* | grep liblua5.2) - ifneq ($(LUA52),) - DEFS+= -DLUA_COMPAT_MODULE -I$(LOCALBASE)/include/lua5.2 - LIBS+= -llua5.2 + ifeq ($(CROSS_COMPILE),) + BUILDER = $(shell which pkg-config) + endif + ifeq ($(BUILDER),) + LUA51 = $(shell ls $(LOCALBASE)/lib/liblua* | grep liblua5.1) + DEFS+= -I$(LOCALBASE)/include + LIBS+= -L$(LOCALBASE)/lib -lm + ifneq ($(LUA51),) + DEFS+= -I$(LOCALBASE)/include/lua5.1 + LIBS+= -llua5.1 else - DEFS+= -DLUA_COMPAT_MODULE -I$(LOCALBASE)/include/lua - LIBS+= -llua + LUA52 = $(shell ls $(LOCALBASE)/lib/liblua* | grep liblua5.2) + ifneq ($(LUA52),) + DEFS+= -DLUA_COMPAT_MODULE -I$(LOCALBASE)/include/lua5.2 + LIBS+= -llua5.2 + else + DEFS+= -DLUA_COMPAT_MODULE -I$(LOCALBASE)/include/lua + LIBS+= -llua + endif endif - endif - else - LUAVER=XX - LUALIBS = $(shell pkg-config --silence-errors --libs lua-5.1) - ifeq ($(LUALIBS),) - LUALIBS = $(shell pkg-config --silence-errors --libs lua5.1) + else + LUAVER=XX + LUALIBS = $(shell pkg-config --silence-errors --libs lua-5.1) ifeq ($(LUALIBS),) - LUALIBS = $(shell pkg-config --silence-errors --libs lua5.2) + LUALIBS = $(shell pkg-config --silence-errors --libs lua5.1) ifeq ($(LUALIBS),) - LUALIBS = $(shell pkg-config --silence-errors --libs lua) - ifneq ($(LUALIBS),) - LUAVER=5X + LUALIBS = $(shell pkg-config --silence-errors --libs lua5.2) + ifeq ($(LUALIBS),) + LUALIBS = $(shell pkg-config --silence-errors --libs lua) + ifneq ($(LUALIBS),) + LUAVER=5X + endif + else + LUAVER=52 endif else - LUAVER=52 + LUAVER=51 endif else - LUAVER=51 + LUAVER=51X endif - else - LUAVER=51X - endif - ifeq ($(LUAVER),XX) - LUA51 = $(shell ls /usr/lib/liblua* | grep liblua5.1) - ifneq ($(LUA51),) - DEFS+= -I/usr/include/lua5.1 - LIBS = -llua5.1 -lm - else - LUA52 = $(shell ls /usr/lib/liblua* | grep liblua5.2) + ifeq ($(LUAVER),XX) + LUA51 = $(shell ls /usr/lib/liblua* | grep liblua5.1) ifneq ($(LUA51),) - DEFS+= -DLUA_COMPAT_MODULE -I/usr/include/lua5.2 - LIBS = -llua5.2 -lm + DEFS+= -I/usr/include/lua5.1 + LIBS = -llua5.1 -lm else - DEFS+= -DLUA_COMPAT_MODULE -I/usr/include/lua - LIBS = -llua -lm + LUA52 = $(shell ls /usr/lib/liblua* | grep liblua5.2) + ifneq ($(LUA51),) + DEFS+= -DLUA_COMPAT_MODULE -I/usr/include/lua5.2 + LIBS = -llua5.2 -lm + else + DEFS+= -DLUA_COMPAT_MODULE -I/usr/include/lua + LIBS = -llua -lm + endif endif - endif - else - ifeq ($(LUAVER),51) - DEFS+= $(shell pkg-config --cflags lua5.1 | sed -e "s/\\\\/'/" -e "s/\\\\\"/\"'/") - LIBS = $(shell pkg-config --libs lua5.1) else - ifeq ($(LUAVER),51X) - DEFS+= $(shell pkg-config --cflags lua-5.1) - LIBS = $(shell pkg-config --libs lua-5.1) + ifeq ($(LUAVER),51) + DEFS+= $(shell pkg-config --cflags lua5.1 | sed -e "s/\\\\/'/" -e "s/\\\\\"/\"'/") + LIBS = $(shell pkg-config --libs lua5.1) else - ifeq ($(LUAVER),52) - DEFS+= -DLUA_COMPAT_MODULE - DEFS+= $(shell pkg-config --cflags lua5.2) - LIBS = $(shell pkg-config --libs lua5.2) + ifeq ($(LUAVER),51X) + DEFS+= $(shell pkg-config --cflags lua-5.1) + LIBS = $(shell pkg-config --libs lua-5.1) else - DEFS+= -DLUA_COMPAT_MODULE - DEFS+= $(shell pkg-config --cflags lua) - LIBS = $(shell pkg-config --libs lua) + ifeq ($(LUAVER),52) + DEFS+= -DLUA_COMPAT_MODULE + DEFS+= $(shell pkg-config --cflags lua5.2) + LIBS = $(shell pkg-config --libs lua5.2) + else + DEFS+= -DLUA_COMPAT_MODULE + DEFS+= $(shell pkg-config --cflags lua) + LIBS = $(shell pkg-config --libs lua) + endif endif endif endif endif + else + DEFS+= $(shell lua-config --include) + LIBS = $(shell lua-config --libs) endif else - DEFS+= $(shell lua-config --include) - LIBS = $(shell lua-config --libs) + # Build using LuaJIT + BUILDER = $(shell which pkg-config) + ifeq ($(BUILDER),) + DEFS+= -I/usr/include/luajit-2.1 + LIBS = -lluajit-5.1 + else + DEFS+= $(shell pkg-config --silence-errors --cflags luajit) + LIBS = $(shell pkg-config --silence-errors --libs luajit) + endif endif DEFS+=-DKAMAILIO_MOD_INTERFACE diff --git a/src/modules/app_lua/README b/src/modules/app_lua/README index 2e2cb1148cd..164cf70c324 100644 --- a/src/modules/app_lua/README +++ b/src/modules/app_lua/README @@ -46,13 +46,14 @@ Daniel-Constantin Mierla List of Examples - 1.1. Set load parameter - 1.2. Set register parameter - 1.3. Set reload parameter - 1.4. lua_dofile usage - 1.5. lua_dostring usage - 1.6. lua_run usage - 1.7. lua_runstring usage + 1.1. Build against LuaJIT libraries + 1.2. Set load parameter + 1.3. Set register parameter + 1.4. Set reload parameter + 1.5. lua_dofile usage + 1.6. lua_dostring usage + 1.7. lua_run usage + 1.8. lua_runstring usage Chapter 1. Admin Guide @@ -120,6 +121,18 @@ Chapter 1. Admin Guide running Kamailio with this module loaded: * liblua5.1-dev - Lua devel library. + This module can be compiled against LuaJIT compiler (instead of + standard Lua). Then this library is needed: + * libluajit-5.1-dev - LuaJIT devel library. + + To enable that, LUAJIT variable has to be set. + + Example 1.1. Build against LuaJIT libraries + E.g: $ LUAJIT="yes" make modules modules=modules/app_lua + + (Warning: LuaJIT version is 5.1, so scripts prepared for higher Lua + versions may not work with LuaJIT) + 3. Parameters 3.1. load (string) @@ -134,7 +147,7 @@ Chapter 1. Admin Guide Default value is “null”. - Example 1.1. Set load parameter + Example 1.2. Set load parameter ... modparam("app_lua", "load", "/usr/local/etc/kamailio/lua/myscript.lua") ... @@ -178,7 +191,7 @@ modparam("app_lua", "load", "/usr/local/etc/kamailio/lua/myscript.lua") Default value is “null”. - Example 1.2. Set register parameter + Example 1.3. Set register parameter ... modparam("app_lua", "register", "sl") ... @@ -190,7 +203,7 @@ modparam("app_lua", "register", "sl") Default value is “0 (off)”. - Example 1.3. Set reload parameter + Example 1.4. Set reload parameter ... modparam("app_lua", "reload", 1) ... @@ -207,7 +220,7 @@ modparam("app_lua", "reload", 1) Execute the Lua script stored in 'path'. The parameter can be a string with pseudo-variables evaluated at runtime. - Example 1.4. lua_dofile usage + Example 1.5. lua_dofile usage ... lua_dofile("/usr/local/etc/kamailio/lua/myscript.lua"); ... @@ -217,7 +230,7 @@ lua_dofile("/usr/local/etc/kamailio/lua/myscript.lua"); Execute the Lua script stored in parameter. The parameter can be a string with pseudo-variables. - Example 1.5. lua_dostring usage + Example 1.6. lua_dostring usage ... if(!lua_dostring("sr.log([[err]], [[----------- Hello World from $fU\n]])")) { @@ -232,7 +245,7 @@ if(!lua_dostring("sr.log([[err]], [[----------- Hello World from $fU\n]])")) loaded at startup via parameter 'load'. Parameters can be strings with pseudo-variables that are evaluated at runtime. - Example 1.6. lua_run usage + Example 1.7. lua_run usage ... if(!lua_run("sr_append_fu_to_reply")) { @@ -248,7 +261,7 @@ lua_run("lua_funcx", "$rU", "2"); string with pseudo-variables. The script is executed in Lua context specific to loaded Lua files at startup. - Example 1.7. lua_runstring usage + Example 1.8. lua_runstring usage ... if(!lua_runstring("sr.log([[err]], [[----------- Hello World from $fU\n]])")) { diff --git a/src/modules/app_lua/doc/app_lua_admin.xml b/src/modules/app_lua/doc/app_lua_admin.xml index 38bf17d7443..edce6a50563 100644 --- a/src/modules/app_lua/doc/app_lua_admin.xml +++ b/src/modules/app_lua/doc/app_lua_admin.xml @@ -75,6 +75,24 @@ + + This module can be compiled against LuaJIT compiler (instead of + standard Lua). Then this library is needed: + + + libluajit-5.1-dev - LuaJIT devel library. + + + + To enable that, LUAJIT variable has to be set. + + Build against LuaJIT libraries + E.g: $ LUAJIT="yes" make modules modules=modules/app_lua + + (Warning: LuaJIT version is 5.1, so scripts prepared for higher Lua versions + may not work with LuaJIT) + +