# 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
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}")
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 */
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 */
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 */
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 */
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);
}
/**
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
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);
luaopen_logger (lua_State * L)
{
- luaL_openlib (L, "rspamd_logger", loggerlib_f, 0);
-
+ luaL_register (L, "rspamd_logger", loggerlib_f);
return 1;
}
static gint
luaopen_util (lua_State *L)
{
- luaL_openlib (L, "rspamd_util", utillib_f, 0);
+ luaL_register (L, "rspamd_util", utillib_f);
return 1;
}
{
lua_State *L;
- L = lua_open ();
+ L = luaL_newstate ();
luaL_openlibs (L);
(void)luaopen_rspamd (L);
#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 }
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 */
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 */
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 */
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 */
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;
luaopen_http (lua_State * L)
{
- luaL_openlib (L, "rspamd_http", httplib_m, 0);
+ luaL_register (L, "rspamd_http", httplib_m);
return 1;
}
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 */
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 */
luaopen_redis (lua_State * L)
{
- luaL_openlib (L, "rspamd_redis", redislib_m, 0);
+ luaL_register (L, "rspamd_redis", redislib_m);
return 1;
}
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 ());
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 */
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 */
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 */
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 */
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 */
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 */
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 */
luaopen_xmlrpc (lua_State * L)
{
- luaL_openlib (L, "rspamd_xmlrpc", xmlrpclib_m, 0);
+ luaL_register (L, "rspamd_xmlrpc", xmlrpclib_m);
return 1;
}
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 */
static gint
luaopen_regexp (lua_State * L)
{
- luaL_openlib (L, "rspamd_regexp", regexplib_m, 0);
+ luaL_register (L, "rspamd_regexp", regexplib_m);
return 1;
}