diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-06-08 16:07:25 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-06-08 16:07:25 +0100 |
commit | 7cc8754ad93be42cf7cd6f1cba68621c93accf89 (patch) | |
tree | 7a433b3ae9ec12b73090afd874b2a12399277cee | |
parent | 4e4beec4cdfa633546a599823280af96b0b61bb7 (diff) | |
download | rspamd-7cc8754ad93be42cf7cd6f1cba68621c93accf89.tar.gz rspamd-7cc8754ad93be42cf7cd6f1cba68621c93accf89.zip |
Adopt to lua 5.2.
-rw-r--r-- | CMakeLists.txt | 62 | ||||
-rw-r--r-- | src/lua/lua_buffer.c | 6 | ||||
-rw-r--r-- | src/lua/lua_cdb.c | 4 | ||||
-rw-r--r-- | src/lua/lua_classifier.c | 4 | ||||
-rw-r--r-- | src/lua/lua_common.c | 14 | ||||
-rw-r--r-- | src/lua/lua_common.h | 21 | ||||
-rw-r--r-- | src/lua/lua_config.c | 10 | ||||
-rw-r--r-- | src/lua/lua_dns.c | 4 | ||||
-rw-r--r-- | src/lua/lua_http.c | 2 | ||||
-rw-r--r-- | src/lua/lua_mempool.c | 4 | ||||
-rw-r--r-- | src/lua/lua_message.c | 2 | ||||
-rw-r--r-- | src/lua/lua_redis.c | 2 | ||||
-rw-r--r-- | src/lua/lua_regexp.c | 4 | ||||
-rw-r--r-- | src/lua/lua_session.c | 6 | ||||
-rw-r--r-- | src/lua/lua_task.c | 8 | ||||
-rw-r--r-- | src/lua/lua_upstream.c | 8 | ||||
-rw-r--r-- | src/lua/lua_xmlrpc.c | 2 | ||||
-rw-r--r-- | src/lua_worker.c | 2 | ||||
-rw-r--r-- | src/plugins/regexp.c | 2 |
19 files changed, 115 insertions, 52 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e08944e14..3c65bfb9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -373,10 +373,60 @@ ENDIF(NOT LOCALSTATES_PREFIX) # Now find libraries and headers -INCLUDE(FindLua51) +# Find lua libraries +IF(NOT LUA_VERSION_MAJOR OR NOT LUA_VERSION_MINOR) + SET(LUA_VERSION_MAJOR "5") + SET(LUA_VERSION_MINOR "1") +ENDIF(NOT LUA_VERSION_MAJOR OR NOT LUA_VERSION_MINOR) + +FIND_PATH(LUA_INCLUDE_DIR lua.h + HINTS + $ENV{LUA_DIR} + PATH_SUFFIXES "include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}" + "include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" + include/lua include + PATHS + /usr/local + /usr + ~/Library/Frameworks + /Library/Frameworks + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +FIND_LIBRARY(LUA_LIBRARY + NAMES lua + "lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}" + "lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" + "lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" + HINTS + $ENV{LUA_DIR} + PATH_SUFFIXES lib64 lib + PATHS + /usr/local + /usr + ~/Library/Frameworks + /Library/Frameworks + /sw + /opt/local + /opt/csw + /opt + DOC "Lua library" +) + +IF(LUA_LIBRARY AND LUA_INCLUDE_DIR) + SET(LUA_FOUND 1) +ENDIF(LUA_LIBRARY AND LUA_INCLUDE_DIR) + # Check for luajit IF(ENABLE_LUAJIT MATCHES "ON") - FIND_LIBRARY(LUAJIT_LIBRARY NAMES luajit51 luajit5.1 luajit-5.1 luajit + FIND_LIBRARY(LUAJIT_LIBRARY NAMES + "luajit${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}" + "luajit${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" + "luajit-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" + luajit HINTS $ENV{LUA_DIR} PATH_SUFFIXES lib64 lib @@ -396,13 +446,7 @@ IF(ENABLE_LUAJIT MATCHES "ON") ENDIF(ENABLE_LUAJIT MATCHES "ON") IF(NOT LUA_FOUND) - # Automatic check failed, check passed variable - IF(LUA_INCLUDE_DIR) - INCLUDE_DIRECTORIES("${LUA_INCLUDE_DIR}") - SET(WITH_LUA 1) - ELSE(LUA_INCLUDE_DIR) - MESSAGE(FATAL_ERROR "Lua not found, lua support is required for working") - ENDIF(LUA_INCLUDE_DIR) + MESSAGE(FATAL_ERROR "Lua not found, lua support is required for working") ELSE(NOT LUA_FOUND) SET(WITH_LUA 1) INCLUDE_DIRECTORIES("${LUA_INCLUDE_DIR}") diff --git a/src/lua/lua_buffer.c b/src/lua/lua_buffer.c index ee2b5d158..37c4fce61 100644 --- a/src/lua/lua_buffer.c +++ b/src/lua/lua_buffer.c @@ -329,14 +329,14 @@ luaopen_io_dispatcher (lua_State * L) lua_pushstring (L, "rspamd{io_dispatcher}"); lua_rawset (L, -3); - luaL_openlib (L, NULL, io_dispatcherlib_m, 0); - luaL_openlib(L, "rspamd_io_dispatcher", io_dispatcherlib_f, 0); + luaL_register (L, NULL, io_dispatcherlib_m); + luaL_register (L, "rspamd_io_dispatcher", io_dispatcherlib_f); lua_pop(L, 1); /* remove metatable from stack */ /* Simple event class */ lua_newclass (L, "rspamd{ev_base}", null_reg); - luaL_openlib (L, "rspamd_ev_base", null_reg, 0); + luaL_register (L, "rspamd_ev_base", null_reg); lua_pop(L, 1); /* remove metatable from stack */ diff --git a/src/lua/lua_cdb.c b/src/lua/lua_cdb.c index dce79a010..6832dfe59 100644 --- a/src/lua/lua_cdb.c +++ b/src/lua/lua_cdb.c @@ -158,8 +158,8 @@ luaopen_cdb (lua_State * L) lua_pushstring (L, "rspamd{cdb}"); lua_rawset (L, -3); - luaL_openlib (L, NULL, cdblib_m, 0); - luaL_openlib (L, "cdb", cdblib_f, 0); + luaL_register (L, NULL, cdblib_m); + luaL_register (L, "cdb", cdblib_f); lua_pop (L, 1); /* remove metatable from stack */ diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c index 202d29af3..33e7ea9f2 100644 --- a/src/lua/lua_classifier.c +++ b/src/lua/lua_classifier.c @@ -412,7 +412,7 @@ gint luaopen_classifier (lua_State * L) { lua_newclass (L, "rspamd{classifier}", classifierlib_m); - luaL_openlib (L, "rspamd_classifier", null_reg, 0); + luaL_register (L, "rspamd_classifier", null_reg); lua_pop (L, 1); /* remove metatable from stack */ @@ -423,7 +423,7 @@ gint luaopen_statfile (lua_State * L) { lua_newclass (L, "rspamd{statfile}", statfilelib_m); - luaL_openlib (L, "rspamd_statfile", null_reg, 0); + luaL_register (L, "rspamd_statfile", null_reg); lua_pop (L, 1); /* remove metatable from stack */ diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 978f7f686..f54380e69 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -210,8 +210,7 @@ lua_newclass (lua_State * L, const gchar *classname, const struct luaL_reg *meth lua_pushstring (L, "class"); /* mt,"__index",it,"class" */ lua_pushstring (L, classname); /* mt,"__index",it,"class",classname */ lua_rawset (L, -3); /* mt,"__index",it */ - - luaL_openlib (L, NULL, methods, 0); + luaL_register (L, NULL, methods); } /** @@ -221,7 +220,7 @@ void lua_newclass_full (lua_State *L, const gchar *classname, const gchar *static_name, const struct luaL_reg *methods, const struct luaL_reg *func) { lua_newclass (L, classname, methods); - luaL_openlib(L, static_name, func, 0); + luaL_register (L, static_name, func); } gint @@ -358,7 +357,7 @@ lua_logger_debug (lua_State * L) gint luaopen_rspamd (lua_State * L) { - luaL_openlib (L, "rspamd", null_reg, 0); + luaL_register (L, "rspamd", null_reg); /* make version string available to scripts */ lua_pushstring (L, "_VERSION"); lua_pushstring (L, RVERSION); @@ -371,8 +370,7 @@ static gint luaopen_logger (lua_State * L) { - luaL_openlib (L, "rspamd_logger", loggerlib_f, 0); - + luaL_register (L, "rspamd_logger", loggerlib_f); return 1; } @@ -380,7 +378,7 @@ luaopen_logger (lua_State * L) static gint luaopen_util (lua_State *L) { - luaL_openlib (L, "rspamd_util", utillib_f, 0); + luaL_register (L, "rspamd_util", utillib_f); return 1; } @@ -406,7 +404,7 @@ init_lua (struct config_file *cfg) { lua_State *L; - L = lua_open (); + L = luaL_newstate (); luaL_openlibs (L); (void)luaopen_rspamd (L); diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 712a51062..f4985cb29 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -10,6 +10,27 @@ #include <lauxlib.h> #include <lualib.h> +#ifndef lua_open +#define lua_open() luaL_newstate() +#endif + +#ifndef luaL_reg +#define luaL_reg luaL_Reg +#endif + +#if LUA_VERSION_NUM > 501 +static inline void +luaL_register (lua_State *L, const gchar *name, const struct luaL_reg *methods) +{ + lua_newtable (L); + luaL_setfuncs (L, methods, 0); + if (name != NULL) { + lua_pushvalue (L, -1); + lua_setglobal (L, name); + } +} +#endif + /* Interface definitions */ #define LUA_FUNCTION_DEF(class, name) static gint lua_##class##_##name(lua_State *L) #define LUA_INTERFACE_DEF(class, name) { #name, lua_##class##_##name } diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index b84879df0..1da50ad19 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -960,7 +960,7 @@ gint luaopen_config (lua_State * L) { lua_newclass (L, "rspamd{config}", configlib_m); - luaL_openlib (L, "rspamd_config", null_reg, 0); + luaL_register (L, "rspamd_config", null_reg); lua_pop (L, 1); /* remove metatable from stack */ @@ -971,7 +971,7 @@ gint luaopen_radix (lua_State * L) { lua_newclass (L, "rspamd{radix}", radixlib_m); - luaL_openlib (L, "rspamd_radix", null_reg, 0); + luaL_register (L, "rspamd_radix", null_reg); lua_pop (L, 1); /* remove metatable from stack */ @@ -982,7 +982,7 @@ gint luaopen_hash_table (lua_State * L) { lua_newclass (L, "rspamd{hash_table}", hashlib_m); - luaL_openlib (L, "rspamd_hash_table", null_reg, 0); + luaL_register (L, "rspamd_hash_table", null_reg); lua_pop (L, 1); /* remove metatable from stack */ @@ -1001,8 +1001,8 @@ luaopen_trie (lua_State * L) lua_pushstring (L, "rspamd{trie}"); lua_rawset (L, -3); - luaL_openlib (L, NULL, trielib_m, 0); - luaL_openlib(L, "rspamd_trie", trielib_f, 0); + luaL_register (L, NULL, trielib_m); + luaL_register (L, "rspamd_trie", trielib_f); lua_pop (L, 1); /* remove metatable from stack */ diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c index 306d15f85..cb011445a 100644 --- a/src/lua/lua_dns.c +++ b/src/lua/lua_dns.c @@ -275,8 +275,8 @@ luaopen_dns_resolver (lua_State * L) lua_pushstring (L, "rspamd{resolver}"); lua_rawset (L, -3); - luaL_openlib (L, NULL, dns_resolverlib_m, 0); - luaL_openlib(L, "rspamd_resolver", dns_resolverlib_f, 0); + luaL_register (L, NULL, dns_resolverlib_m); + luaL_register (L, "rspamd_resolver", dns_resolverlib_f); lua_pop (L, 1); /* remove metatable from stack */ return 1; diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 7bbe07187..9df019af4 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -622,7 +622,7 @@ gint luaopen_http (lua_State * L) { - luaL_openlib (L, "rspamd_http", httplib_m, 0); + luaL_register (L, "rspamd_http", httplib_m); return 1; } diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c index 9d6168fa3..7b95d6c0c 100644 --- a/src/lua/lua_mempool.c +++ b/src/lua/lua_mempool.c @@ -228,8 +228,8 @@ luaopen_mempool (lua_State * L) lua_pushstring (L, "rspamd{mempool}"); lua_rawset (L, -3); - luaL_openlib (L, NULL, mempoollib_m, 0); - luaL_openlib(L, "rspamd_mempool", mempoollib_f, 0); + luaL_register (L, NULL, mempoollib_m); + luaL_register (L, "rspamd_mempool", mempoollib_f); lua_pop (L, 1); /* remove metatable from stack */ diff --git a/src/lua/lua_message.c b/src/lua/lua_message.c index f1b40fe9d..f02178d1a 100644 --- a/src/lua/lua_message.c +++ b/src/lua/lua_message.c @@ -204,7 +204,7 @@ gint luaopen_message (lua_State * L) { lua_newclass (L, "rspamd{message}", msglib_m); - luaL_openlib (L, "rspamd_message", null_reg, 0); + luaL_register (L, "rspamd_message", null_reg); lua_pop (L, 1); /* remove metatable from stack */ diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index e312092cb..a9006b773 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -343,7 +343,7 @@ gint luaopen_redis (lua_State * L) { - luaL_openlib (L, "rspamd_redis", redislib_m, 0); + luaL_register (L, "rspamd_redis", redislib_m); return 1; } diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c index fe844a9cc..f09116c93 100644 --- a/src/lua/lua_regexp.c +++ b/src/lua/lua_regexp.c @@ -266,8 +266,8 @@ luaopen_glib_regexp (lua_State * L) lua_pushstring (L, "rspamd{regexp}"); lua_rawset (L, -3); - luaL_openlib (L, NULL, regexplib_m, 0); - luaL_openlib(L, "regexp", regexplib_f, 0); + luaL_register (L, NULL, regexplib_m); + luaL_register (L, "regexp", regexplib_f); regexp_static_pool = memory_pool_new (memory_pool_get_size ()); diff --git a/src/lua/lua_session.c b/src/lua/lua_session.c index db8d0ef23..9d0387edc 100644 --- a/src/lua/lua_session.c +++ b/src/lua/lua_session.c @@ -301,14 +301,14 @@ luaopen_session (lua_State * L) lua_pushstring (L, "rspamd{session}"); lua_rawset (L, -3); - luaL_openlib (L, NULL, sessionlib_m, 0); - luaL_openlib(L, "rspamd_session", sessionlib_f, 0); + luaL_register (L, NULL, sessionlib_m); + luaL_register (L, "rspamd_session", sessionlib_f); lua_pop (L, 1); /* remove metatable from stack */ /* Simple event class */ lua_newclass (L, "rspamd{event}", eventlib_m); - luaL_openlib (L, "rspamd_event", null_reg, 0); + luaL_register (L, "rspamd_event", null_reg); lua_pop (L, 1); /* remove metatable from stack */ diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 154eed731..014a994e0 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -2051,7 +2051,7 @@ gint luaopen_textpart (lua_State * L) { lua_newclass (L, "rspamd{textpart}", textpartlib_m); - luaL_openlib (L, "rspamd_textpart", null_reg, 0); + luaL_register (L, "rspamd_textpart", null_reg); lua_pop (L, 1); /* remove metatable from stack */ @@ -2062,7 +2062,7 @@ gint luaopen_mimepart (lua_State * L) { lua_newclass (L, "rspamd{mimepart}", mimepartlib_m); - luaL_openlib (L, "rspamd_mimepart", null_reg, 0); + luaL_register (L, "rspamd_mimepart", null_reg); lua_pop (L, 1); /* remove metatable from stack */ @@ -2073,7 +2073,7 @@ gint luaopen_image (lua_State * L) { lua_newclass (L, "rspamd{image}", imagelib_m); - luaL_openlib (L, "rspamd_image", null_reg, 0); + luaL_register (L, "rspamd_image", null_reg); lua_pop (L, 1); /* remove metatable from stack */ @@ -2084,7 +2084,7 @@ gint luaopen_url (lua_State * L) { lua_newclass (L, "rspamd{url}", urllib_m); - luaL_openlib (L, "rspamd_url", null_reg, 0); + luaL_register (L, "rspamd_url", null_reg); lua_pop (L, 1); /* remove metatable from stack */ diff --git a/src/lua/lua_upstream.c b/src/lua/lua_upstream.c index 16a925570..855e9ff4a 100644 --- a/src/lua/lua_upstream.c +++ b/src/lua/lua_upstream.c @@ -519,8 +519,8 @@ luaopen_upstream (lua_State * L) lua_pushstring (L, "rspamd{upstream_list}"); lua_rawset (L, -3); - luaL_openlib (L, NULL, upstream_list_m, 0); - luaL_openlib (L, "upstream_list", upstream_list_f, 0); + luaL_register (L, NULL, upstream_list_m); + luaL_register (L, "upstream_list", upstream_list_f); lua_pop (L, 1); /* remove metatable from stack */ @@ -533,8 +533,8 @@ luaopen_upstream (lua_State * L) lua_pushstring (L, "rspamd{upstream}"); lua_rawset (L, -3); - luaL_openlib (L, NULL, upstream_m, 0); - luaL_openlib (L, "upstream", upstream_f, 0); + luaL_register (L, NULL, upstream_m); + luaL_register (L, "upstream", upstream_f); lua_pop (L, 1); /* remove metatable from stack */ diff --git a/src/lua/lua_xmlrpc.c b/src/lua/lua_xmlrpc.c index 25f15ed7d..57691cda5 100644 --- a/src/lua/lua_xmlrpc.c +++ b/src/lua/lua_xmlrpc.c @@ -552,7 +552,7 @@ gint luaopen_xmlrpc (lua_State * L) { - luaL_openlib (L, "rspamd_xmlrpc", xmlrpclib_m, 0); + luaL_register (L, "rspamd_xmlrpc", xmlrpclib_m); return 1; } diff --git a/src/lua_worker.c b/src/lua_worker.c index 723c48707..0cadb7eb2 100644 --- a/src/lua_worker.c +++ b/src/lua_worker.c @@ -104,7 +104,7 @@ static gint luaopen_lua_worker (lua_State * L) { lua_newclass (L, "rspamd{worker}", lua_workerlib_m); - luaL_openlib (L, "rspamd_worker", null_reg, 0); + luaL_register (L, "rspamd_worker", null_reg); lua_pop (L, 1); /* remove metatable from stack */ diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 91543d2c4..b838b1ee6 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -175,7 +175,7 @@ task_cache_check (struct worker_task *task, struct rspamd_regexp *re) static gint luaopen_regexp (lua_State * L) { - luaL_openlib (L, "rspamd_regexp", regexplib_m, 0); + luaL_register (L, "rspamd_regexp", regexplib_m); return 1; } |