v0.9.2 Support for lua 5.2
authorMyhailo Danylenko <isbear@ukrpost.net>
Wed, 28 Nov 2012 01:56:15 +0200
changeset 54 6bef2082e5f9
parent 53 2dcfa81100e4
child 55 25f8359ed8cf
v0.9.2 Support for lua 5.2
CMakeLists.txt
config.h.in
docs/readme.mdwn
lm_connection.c
lm_message.c
lm_message_handler.c
lm_message_node.c
lm_proxy.c
lm_ssl.c
--- a/CMakeLists.txt	Wed Nov 28 01:55:12 2012 +0200
+++ b/CMakeLists.txt	Wed Nov 28 01:56:15 2012 +0200
@@ -16,23 +16,36 @@
 
 cmake_minimum_required(VERSION 2.6)
 project(lua-lm C)
-set(PROJECT_VERSION "0.9.1")
+set(PROJECT_VERSION "0.9.2")
 
 ## User options
-option(DEBUG "Enable debugging output" OFF)
-set(TEST_USER "test@jabber.org" CACHE STRING "Testing: Your jabber account name")
-set(TEST_PASSWORD "greatsecret" CACHE STRING "Testing: Password for your jabber account")
-set(TEST_TO "test@jabber.org/mcabber" CACHE STRING "Testing: Target jabber entity")
+option(DEBUG      "Enable debugging output" OFF)
+option(WANT_LUA52 "Force Lua 5.2 usage"     OFF)
+set(TEST_USER        "test@jabber.org" CACHE STRING "Testing: Your jabber account name")
+set(TEST_PASSWORD    "greatsecret" CACHE STRING "Testing: Password for your jabber account")
+set(TEST_TO          "test@jabber.org/mcabber" CACHE STRING "Testing: Target jabber entity")
 set(TEST_FINGERPRINT "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff" CACHE STRING "Testing: Your jabber server SSL fingerprint")
 
 ## Gather information about system
-find_package(Lua51 REQUIRED)
-find_program(LUA_EXECUTABLE lua lua5.1 luanoreadline)
+find_package(PkgConfig REQUIRED)
+if(NOT WANT_LUA52)
+	find_package(Lua51)
+endif()
+if(WANT_LUA52 OR NOT LUA51_FOUND)
+	pkg_check_modules(LUA REQUIRED lua5.2)
+	set(LUA_VERSION "5.2")
+	set(LUA_DEB_DEP "liblua5.2")
+	set(HAVE_LUA52 "1")
+else()
+	set(LUA_VERSION "5.1")
+	set(LUA_DEB_DEP "liblua5.1-0")
+	set(LUA_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
+endif()
+find_program(LUA_EXECUTABLE lua${LUA_VERSION} lua luanoreadline)
 if(LUA_EXECUTABLE)
-	execute_process(COMMAND ${LUA_EXECUTABLE} -e "print ( package.path )" OUTPUT_VARIABLE LUA_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
+	execute_process(COMMAND ${LUA_EXECUTABLE} -e "print ( package.path )"  OUTPUT_VARIABLE LUA_PATH  OUTPUT_STRIP_TRAILING_WHITESPACE)
 	execute_process(COMMAND ${LUA_EXECUTABLE} -e "print ( package.cpath )" OUTPUT_VARIABLE LUA_CPATH OUTPUT_STRIP_TRAILING_WHITESPACE)
 endif()
-find_package(PkgConfig REQUIRED)
 pkg_check_modules(GLIB REQUIRED glib-2.0)
 pkg_check_modules(LM REQUIRED loudmouth-1.0)
 include(CheckFunctionExists)
@@ -54,7 +67,7 @@
 	set(DEBUG_COMPILE_FLAGS "-g")
 endif()
 configure_file(config.h.in config.h)
-include_directories(SYSTEM ${LUA_INCLUDE_DIR} ${GLIB_INCLUDE_DIRS} ${LM_INCLUDE_DIRS})
+include_directories(SYSTEM ${LUA_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS} ${LM_INCLUDE_DIRS})
 target_link_libraries(loudmouth ${LUA_LIBRARIES} ${GLIB_LIBRARIES} ${LM_LIBRARIES})
 include_directories(${lua-lm_SOURCE_DIR} ${lua-lm_BINARY_DIR})
 set_target_properties(loudmouth PROPERTIES
@@ -73,7 +86,7 @@
 endif()
 
 ## Packaging information
-set(CPACK_PACKAGE_NAME liblua5.1-loudmouth)
+set(CPACK_PACKAGE_NAME lua${LUA_VERSION}-loudmouth)
 set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
 set(CPACK_PACKAGE_VENDOR "IsBear")
 set(CPACK_PACKAGE_CONTACT "Myhailo Danylenko <isbear@ukrpost.net>")
@@ -87,7 +100,7 @@
 set(CPACK_DEBIAN_PACKAGE_SECTION libs)
 # XXX: tmp=`tempfile`; obj=${lua-lm_BINARY_DIR}/loudmouth.so; ldd $obj > $tmp; objdump -p $obj | \grep NEEDED | sed -e 's/.*NEEDED *//' | xargs -I "{}" grep -F "{}" $tmp | sed -e 's/.*=> *\(\S*\).*/\1/' | xargs dpkg -S | cut -d : -f 1 | sort -u ; \rm $tmp
 # TODO: versions
-set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libglib2.0-0, liblua5.1-0, libloudmouth1-0")
+set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libglib2.0-0, ${LUA_DEB_DEP}, libloudmouth1-0")
 find_program(DPKG_EXECUTABLE dpkg)
 if(DPKG_EXECUTABLE)
 	execute_process(COMMAND ${DPKG_EXECUTABLE} --print-architecture OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE)
@@ -100,8 +113,8 @@
 include(CPack)
 
 ## Set up installer
-install(TARGETS loudmouth DESTINATION lib/lua/5.1)
-install(FILES lm.lua DESTINATION share/lua/5.1)
+install(TARGETS loudmouth DESTINATION lib/lua/${LUA_VERSION})
+install(FILES lm.lua DESTINATION share/lua/${LUA_VERSION})
 install(FILES test.lua DESTINATION share/doc/${CPACK_PACKAGE_NAME}/examples)
 if(DOCGEN_EXECUTABLE)
 	install(FILES ${lua-lm_BINARY_DIR}/loudmouth.html DESTINATION share/doc/${CPACK_PACKAGE_NAME})
--- a/config.h.in	Wed Nov 28 01:55:12 2012 +0200
+++ b/config.h.in	Wed Nov 28 01:56:15 2012 +0200
@@ -22,12 +22,20 @@
 // define this to enable debugging output
 #cmakedefine DEBUG
 
+// define this, if you are building with liblua 5.2
+#cmakedefine HAVE_LUA52
+
 // define this, if your loudmouth have lm_connection_get_keep_alive_rate ()
 #cmakedefine HAVE_LM_CONNECTION_GET_KEEP_ALIVE_RATE
 
 // define this, if your loudmouth have lm_connection_unregister_reply_handler ()
 #cmakedefine HAVE_LM_CONNECTION_UNREGISTER_REPLY_HANDLER
 
+#ifndef HAVE_LUA52
+#  define lua_rawlen lua_objlen
+#  define luaL_setfuncs(STATE, REGTABLE, IGZERO) luaL_register ( STATE, NULL, REGTABLE )
+#endif
+
 #ifdef DEBUG
 #  include <glib.h>
 
--- a/docs/readme.mdwn	Wed Nov 28 01:55:12 2012 +0200
+++ b/docs/readme.mdwn	Wed Nov 28 01:56:15 2012 +0200
@@ -1,7 +1,7 @@
 
 # Loudmouth interface for lua
 
-This interface to loudmouth XMPP client library for lua 5.1.
+This interface to loudmouth XMPP client library for lua 5.1 or 5.2.
 
 Main loudmouth project is now unmaintained, but mcabber community keeps
 working version with some improvements at
@@ -44,7 +44,7 @@
 Debian users can instead of make install do:
 
     $ make package
-    # dpkg -i liblua5.1-loudmouth_*.deb
+    # dpkg -i lua5.?-loudmouth_*.deb
 
 Users of other systems can set other CPack generator using cache editor.
 
--- a/lm_connection.c	Wed Nov 28 01:55:12 2012 +0200
+++ b/lm_connection.c	Wed Nov 28 01:56:15 2012 +0200
@@ -596,10 +596,10 @@
 	luaL_newmetatable (L, "loudmouth.connection");
 	lua_pushvalue (L, -1);
 	lua_setfield (L, -2, "__index");
-	luaL_register (L, NULL, reg_m_lm_connection);
+	luaL_setfuncs (L, reg_m_lm_connection, 0);
 	lua_pop (L, 1);
 	lua_newtable (L); // XXX we can specify here exact amount of fields
-	luaL_register (L, NULL, reg_f_lm_connection);
+	luaL_setfuncs (L, reg_f_lm_connection, 0);
 	return 1;
 }
 
--- a/lm_message.c	Wed Nov 28 01:55:12 2012 +0200
+++ b/lm_message.c	Wed Nov 28 01:56:15 2012 +0200
@@ -301,10 +301,10 @@
 	luaL_newmetatable (L, "loudmouth.message");
 	lua_pushvalue (L, -1);
 	lua_setfield (L, -2, "__index");
-	luaL_register (L, NULL, reg_m_lm_message);
+	luaL_setfuncs (L, reg_m_lm_message, 0);
 	lua_pop (L, 1);
 	lua_newtable (L); // XXX we can specify here exact amount of fields
-	luaL_register (L, NULL, reg_f_lm_message);
+	luaL_setfuncs (L, reg_f_lm_message, 0);
 	return 1;
 }
 
--- a/lm_message_handler.c	Wed Nov 28 01:55:12 2012 +0200
+++ b/lm_message_handler.c	Wed Nov 28 01:56:15 2012 +0200
@@ -146,10 +146,10 @@
 	luaL_newmetatable (L, "loudmouth.message_handler");
 	lua_pushvalue (L, -1);
 	lua_setfield (L, -2, "__index");
-	luaL_register (L, NULL, reg_m_lm_handler);
+	luaL_setfuncs (L, reg_m_lm_handler, 0);
 	lua_pop (L, 1);
 	lua_newtable (L); // XXX we can specify here exact amount of fields
-	luaL_register (L, NULL, reg_f_lm_handler);
+	luaL_setfuncs (L, reg_f_lm_handler, 0);
 	return 1;
 }
 
--- a/lm_message_node.c	Wed Nov 28 01:55:12 2012 +0200
+++ b/lm_message_node.c	Wed Nov 28 01:56:15 2012 +0200
@@ -306,10 +306,10 @@
 	luaL_newmetatable (L, "loudmouth.message_node");
 	lua_pushvalue (L, -1);
 	lua_setfield (L, -2, "__index");
-	luaL_register (L, NULL, reg_m_lm_node);
+	luaL_setfuncs (L, reg_m_lm_node, 0);
 	lua_pop (L, 1);
 	lua_newtable (L); // XXX we can specify here exact amount of fields
-	luaL_register (L, NULL, reg_f_lm_node);
+	luaL_setfuncs (L, reg_f_lm_node, 0);
 	return 1;
 }
 
--- a/lm_proxy.c	Wed Nov 28 01:55:12 2012 +0200
+++ b/lm_proxy.c	Wed Nov 28 01:56:15 2012 +0200
@@ -184,10 +184,10 @@
 	luaL_newmetatable (L, "loudmouth.proxy");
 	lua_pushvalue (L, -1);
 	lua_setfield (L, -2, "__index");
-	luaL_register (L, NULL, reg_m_lm_proxy);
+	luaL_setfuncs (L, reg_m_lm_proxy, 0);
 	lua_pop (L, 1);
 	lua_newtable (L); // XXX we can specify here exact amount of fields
-	luaL_register (L, NULL, reg_f_lm_proxy);
+	luaL_setfuncs (L, reg_f_lm_proxy, 0);
 	return 1;
 }
 
--- a/lm_ssl.c	Wed Nov 28 01:55:12 2012 +0200
+++ b/lm_ssl.c	Wed Nov 28 01:56:15 2012 +0200
@@ -95,7 +95,7 @@
 		gchar buffer[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
 		const char *fingerprint = luaL_checkstring (L, 1);
 
-		if (lua_objlen (L, 1) > 46)
+		if (lua_rawlen (L, 1) > 46)
 			string2fingerprint (fingerprint, buffer);
 		ssl = lm_ssl_new (buffer, NULL, NULL, NULL);
 	} else {
@@ -104,7 +104,7 @@
 
 		if (args > 1) {
 			const char *fingerprint = luaL_checkstring (L, 1);
-			if (lua_objlen (L, 1) > 46)
+			if (lua_rawlen (L, 1) > 46)
 				string2fingerprint (fingerprint, buffer);
 			luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected");
 		} else
@@ -224,10 +224,10 @@
 	luaL_newmetatable (L, "loudmouth.ssl");
 	lua_pushvalue (L, -1);
 	lua_setfield (L, -2, "__index");
-	luaL_register (L, NULL, reg_m_lm_ssl);
+	luaL_setfuncs (L, reg_m_lm_ssl, 0);
 	lua_pop (L, 1);
 	lua_newtable (L); // XXX we can specify here exact amount of fields
-	luaL_register (L, NULL, reg_f_lm_ssl);
+	luaL_setfuncs (L, reg_f_lm_ssl, 0);
 	return 1;
 }