--- a/CMakeLists.txt Fri Mar 05 19:15:08 2010 +0200
+++ b/CMakeLists.txt Fri Mar 05 19:49:09 2010 +0200
@@ -22,7 +22,6 @@
option(DEBUG "Enable debugging output" ON)
option(LLM_CONNECTION_ENABLE "Enable exposing of mcabber loudmouth connection to lua" ON)
option(LLM_LOG_HANDLER "Enable registration of log messages handler for lua-loudmouth library's messages" ON)
-set(MCABBER_INCLUDE_DIR "/usr/include" CACHE FILEPATH "Path to mcabber headers")
set(ML_SOURCE_PRIORITY G_PRIORITY_HIGH_IDLE CACHE STRING "Glib event source priority for timeout and bgread")
set(ML_BGREAD_BUFFER 4096 CACHE STRING "Background pipe reading buffer size")
@@ -31,34 +30,31 @@
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(GMODULE REQUIRED gmodule-2.0)
-# XXX: we need only headers
-if(LLM_CONNECTION_ENABLE)
- pkg_check_modules(LM REQUIRED loudmouth-1.0)
-endif()
+pkg_check_modules(MCABBER REQUIRED mcabber)
find_package(Perl)
link_directories(${GLIB_LIBRARY_DIRS}
${GMODULE_LIBRARY_DIRS}
- ${LM_LIBRARY_DIRS})
+ ${MCABBER_LIBRARY_DIRS})
## Define targets
add_library(lua MODULE main.c util.c)
-get_target_property(lua_SOURCES lua SOURCES)
## Set up compiler
configure_file(config.h.in config.h ESCAPE_QUOTES)
include_directories(SYSTEM ${LUA_INCLUDE_DIR}
${GLIB_INCLUDE_DIRS}
${GMODULE_INCLUDE_DIRS}
- ${LM_INCLUDE_DIRS}
- ${MCABBER_INCLUDE_DIR})
+ ${MCABBER_INCLUDE_DIRS})
target_link_libraries(lua ${LUA_LIBRARIES}
${GLIB_LIBRARIES}
- ${GMODULE_LIBRARIES})
+ ${GMODULE_LIBRARIES}
+ ${MCABBER_LIBRARRIES})
include_directories(${lua_SOURCE_DIR}
${lua_BINARY_DIR})
## Extra targets
if(PERL_FOUND)
+ get_target_property(lua_SOURCES lua SOURCES)
add_custom_command(OUTPUT ${lua_BINARY_DIR}/lua.html COMMAND ${PERL_EXECUTABLE} ${lua_SOURCE_DIR}/docgen.pl ${lua_SOURCES} > ${lua_BINARY_DIR}/lua.html DEPENDS ${lua_SOURCE_DIR}/docgen.pl ${lua_SOURCES} WORKING_DIRECTORY ${lua_SOURCE_DIR})
add_custom_target(doc ALL DEPENDS ${lua_BINARY_DIR}/lua.html)
endif()
--- a/README Fri Mar 05 19:15:08 2010 +0200
+++ b/README Fri Mar 05 19:49:09 2010 +0200
@@ -5,10 +5,9 @@
scripts working with this module.
To install it, you will need:
-- lua 5.1 library and headers
-- glib (with gmodule) library and headers
-- loudmouth headers
-- mcabber headers
+- lua 5.1
+- glib
+- mcabber
- cmake
- perl (optional)
@@ -22,11 +21,12 @@
Debian users can instead of make install do
$ fakeroot make package
-# dpkg -i mcabber-lua*.deb
+# dpkg -i libmcabber-lua*.deb
This code underlies terms of GNU GPL v2 or later.
-I will be happy to get feedback, patches, suggestions, etc.
+I willi be happy to get feedback, patches, suggestions, etc.
+You can send me email or contact via jabber <isbear@unixzone.org.ua>.
-- Myhailo Danylenko <isbear@ukrpost.net>
--- a/examples/lua.rc Fri Mar 05 19:15:08 2010 +0200
+++ b/examples/lua.rc Fri Mar 05 19:49:09 2010 +0200
@@ -29,5 +29,5 @@
# filter evil stanzas
set lua_filter_evil = 0
-load lua
+module load lua
--- a/main.c Fri Mar 05 19:15:08 2010 +0200
+++ b/main.c Fri Mar 05 19:49:09 2010 +0200
@@ -17,7 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <glib.h>
-#include <gmodule.h>
+#include <gmodule.h> // g_module_*
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
@@ -37,10 +37,22 @@
#include <mcabber/settings.h> // settings_set, settings_del, settings_get
#include <mcabber/compl.h> // compl_new_category, compl_add_category_word, compl_del_category_word
#include <mcabber/events.h> // evs_*
+#include <mcabber/modules.h> // module_info_t
#include "config.h"
#include "util.h"
+// module description
+static void mlua_init (void);
+static void mlua_uninit (void);
+
+module_info_t info_lua = {
+ .mcabber_version = "0.10.0",
+ .requires = NULL,
+ .init = mlua_init,
+ .uninit = mlua_uninit,
+};
+
// global lua state object, necessary for uninitialization function
static lua_State *lua = NULL;
@@ -1270,11 +1282,22 @@
const gchar *g_module_check_init (GModule *module)
{
lua = lua_newstate (lua_alloc, NULL);
- if (!lua) {
- scr_LogPrint (LPRINT_LOGNORM, "lua: Initialization error");
+ if (!lua)
return "Lua initialization error";
+ else
+ return NULL;
+}
+
+void g_module_unload (GModule *module)
+{
+ if (lua) {
+ lua_close (lua);
+ lua = NULL;
}
+}
+static void mlua_init (void)
+{
luaL_openlibs (lua);
luaL_register (lua, "main", lua_reg_main);
@@ -1303,7 +1326,6 @@
lua_lm_log_handler_id = g_log_set_handler ("lua-lm", G_LOG_LEVEL_MASK, (GLogFunc) lua_lm_log_handler, NULL);
#endif
-#if 1
{
char *initfile = expand_filename (settings_opt_get ("lua_init_filename"));
@@ -1321,7 +1343,6 @@
g_free (initfile);
}
}
-#endif
hk_add_handler ((hk_handler_t) lua_hook, ~((guint32)0), lua);
@@ -1332,8 +1353,6 @@
};
lua_hook (0, args, lua);
}
-
- return NULL;
}
static void lua_events_cancel (gpointer data, gpointer ignore)
@@ -1389,7 +1408,7 @@
compl_del_category (id);
}
-void g_module_unload (GModule *module)
+static void mlua_uninit (void)
{
if (lua) {
hk_arg_t args[] = {