]> source.dussan.org Git - rspamd.git/commitdiff
Adopt to lua 5.2.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 8 Jun 2013 15:07:25 +0000 (16:07 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 8 Jun 2013 15:07:25 +0000 (16:07 +0100)
19 files changed:
CMakeLists.txt
src/lua/lua_buffer.c
src/lua/lua_cdb.c
src/lua/lua_classifier.c
src/lua/lua_common.c
src/lua/lua_common.h
src/lua/lua_config.c
src/lua/lua_dns.c
src/lua/lua_http.c
src/lua/lua_mempool.c
src/lua/lua_message.c
src/lua/lua_redis.c
src/lua/lua_regexp.c
src/lua/lua_session.c
src/lua/lua_task.c
src/lua/lua_upstream.c
src/lua/lua_xmlrpc.c
src/lua_worker.c
src/plugins/regexp.c

index e08944e147650c403632bdc379db3add0ed55729..3c65bfb9cc15a02ae566c5015ab4d10e4942cda6 100644 (file)
@@ -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}")
index ee2b5d158697b17f9049528c6dc9a69b44d0c64b..37c4fce61dc4f4f02da66d05c6c046fa9fc4f808 100644 (file)
@@ -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 */
 
index dce79a0107d89f6f13ab35ed2c6a69ac970eb42e..6832dfe5971c1691463a7bca78b42f7318adf1b0 100644 (file)
@@ -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 */
 
index 202d29af3afcffcc1308f71394226131a0ee02cb..33e7ea9f27aaccfecbb65f136c5eefac53f3474c 100644 (file)
@@ -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 */
 
index 978f7f686aaaa85588cddb65e952f288cdde5043..f54380e696b86e91ebbdd017f3b89e31e176d4c0 100644 (file)
@@ -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);
index 712a51062439446dd320c65f217f93a002649dd0..f4985cb29bacf4fa60f59e378056598ec5588527 100644 (file)
 #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 }
index b84879df0c89139a80e3986b76cb4c800dbcd184..1da50ad19380f098302627f3fac21b03edb19c56 100644 (file)
@@ -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 */
 
index 306d15f855ca769c933dd6932c16c72b65cedfac..cb011445a0b43f2b4e2a25cb4658c180b8e3d024 100644 (file)
@@ -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;       
index 7bbe0718739639ec2eb37cc3298ac87c0966c324..9df019af4d7827b12ba02249d1b1c18c4b036c54 100644 (file)
@@ -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;
 }
index 9d6168fa3a79e7f5611147beb4f4364bfd7b2c02..7b95d6c0cf5fd5e5fb1f6fd1c4d9edea8844822e 100644 (file)
@@ -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 */
 
index f1b40fe9d31b3e7eafb358aad06f2b1ab3d52122..f02178d1a33bcbc9f5483db30eddaf479b28ec88 100644 (file)
@@ -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 */
 
index e312092cba8d825aba922d29fe0eaa4f7cf7b7f7..a9006b773ded027b9b7affa4ba185056bd14a478 100644 (file)
@@ -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;
 }
index fe844a9ccf6b8c1012f4349587afb579f2f79a52..f09116c93c887172da4a1db4770d2f885a3ddc20 100644 (file)
@@ -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 ());
 
index db8d0ef23518901d4b4ac25526ff743459134903..9d0387edcad7f64cbf619f8ce37cb00c91dfc5e9 100644 (file)
@@ -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 */
 
index 154eed731dcd1837dc035f6214bfea7b9140504f..014a994e0f845bcc9057e6d08a3d40e958d086f3 100644 (file)
@@ -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 */
 
index 16a925570973543b75bfa0f9a500397e8141c2c4..855e9ff4accfbc06853b598043339d7d7260e81e 100644 (file)
@@ -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 */
 
index 25f15ed7dc284665405e4cf49f0619e012d03975..57691cda5c600f8a978cb2522821786400d88b39 100644 (file)
@@ -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;
 }
index 723c48707041d1ec2d1631d585756d2e6d9b14a2..0cadb7eb2d1299a56af99d8a9beeb71b511b834c 100644 (file)
@@ -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 */
 
index 91543d2c4011fd5603e5ce397c3a31472e50fa9b..b838b1ee654dc9c399ab4f40d146fdd7819b8f54 100644 (file)
@@ -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;
 }