--- a/CMakeLists.txt Sat Nov 07 22:36:02 2015 +0200
+++ b/CMakeLists.txt Sat Mar 05 18:34:07 2016 +0200
@@ -1,4 +1,4 @@
-## Copyright 2009-2012 Myhailo Danylenko
+## Copyright 2009-2016 Myhailo Danylenko
# This file is part of mcabber-lua.
#
# mcabber-lua is free software: you can redistribute it and/or modify
@@ -16,11 +16,10 @@
cmake_minimum_required(VERSION 2.6)
project(lua C)
-set(PROJECT_VERSION "0.0.3")
+set(PROJECT_VERSION "0.0.4")
## User options
option(DEBUG "Enable debugging output" ON)
-option(WANT_LUA52 "Use lua 5.2 instead of 5.1" OFF)
option(ENABLE_LUA_ALIAS "Enable aliasing command '/lua' to corresponding '/lua5.x' at module loading time" 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)
@@ -28,21 +27,25 @@
set(ML_BGREAD_BUFFER 4096 CACHE STRING "Background pipe reading buffer size")
set(OPT_MLUA_RC "lua_init_filename" CACHE STRING "Mcabber option name to specify lua initialization file")
set(OPT_MLUA_LM_DEBUG "lua_lm_debug" CACHE STRING "Mcabber option name to enable/disable lua logging of LM messages")
+set(WANT_LUA "AUTO" CACHE STRING "Lua version to use (You'll have to define this with -DWANT_LUA=LUAX.X)")
+set_property(CACHE WANT_LUA PROPERTY STRINGS "AUTO" "LUA5.1" "LUA5.2" "LUA5.3")
## Gather information about system
find_package(PkgConfig REQUIRED)
-if(NOT WANT_LUA52)
- find_package(Lua51)
+if(WANT_LUA STREQUAL "LUA5.3")
+ find_package(Lua 5.3 EXACT REQUIRED)
+elseif(WANT_LUA STREQUAL "LUA5.2")
+ find_package(Lua 5.2 EXACT REQUIRED)
+elseif(WANT_LUA STREQUAL "LUA5.1")
+ find_package(Lua 5.1 EXACT REQUIRED)
+else()
+ find_package(Lua 5.1 REQUIRED)
endif()
-if(WANT_LUA52 OR NOT LUA51_FOUND)
- pkg_check_modules(LUA REQUIRED lua5.2)
- set(LUA_VERSION "5.2")
- set(HAVE_LUA52 "1")
-else()
- set(LUA_VERSION "5.1")
- set(LUA_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
+set(LUA_VERSION "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
+set(LUA_MODULENAME "lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}")
+if(LUA_VERSION VERSION_EQUAL "5.1")
+ set(LUA51_COMPATIBILITY TRUE)
endif()
-string(REPLACE "." "" LUA_MODULENAME "lua${LUA_VERSION}")
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(GMODULE REQUIRED gmodule-2.0)
pkg_check_modules(MCABBER REQUIRED mcabber)
@@ -70,7 +73,7 @@
## Set up compiler
configure_file(config.h.in config.h ESCAPE_QUOTES)
-include_directories(SYSTEM ${LUA_INCLUDE_DIRS}
+include_directories(SYSTEM ${LUA_INCLUDE_DIR}
${GLIB_INCLUDE_DIRS}
${GMODULE_INCLUDE_DIRS}
${MCABBER_INCLUDE_DIRS})
@@ -80,7 +83,9 @@
${MCABBER_LIBRARRIES})
include_directories(${lua_SOURCE_DIR}
${lua_BINARY_DIR})
-set_target_properties(lua PROPERTIES COMPILE_FLAGS "-Wall" OUTPUT_NAME "${LUA_MODULENAME}")
+set_target_properties(lua PROPERTIES
+ COMPILE_FLAGS "-Wall"
+ OUTPUT_NAME "${LUA_MODULENAME}")
## Extra targets
if(DOCGEN_EXECUTABLE)
@@ -132,7 +137,7 @@
endif()
install(DIRECTORY examples DESTINATION share/doc/${CPACK_PACKAGE_NAME} PATTERN "*~" EXCLUDE)
install(FILES docs/readme.mdwn docs/todo.mdwn COPYING DESTINATION share/doc/${CPACK_PACKAGE_NAME})
-install(FILES help/en/hlp_lua.txt DESTINATION share/mcabber RENAME hlp_lua${LUA_VERSION}.txt) # XXX localizations/other help
+install(FILES help/en/hlp_lua.txt DESTINATION share/mcabber RENAME hlp_lua${LUA_MODULENAME}.txt) # XXX localizations/other help
install(FILES ${PROJECT_BINARY_DIR}/${LUA_MODULENAME}.avv DESTINATION share/mcabber/avv/modules RENAME ${LUA_MODULENAME})
## The End ## vim: se ts=4 sw=4: ##
--- a/config.h.in Sat Nov 07 22:36:02 2015 +0200
+++ b/config.h.in Sat Mar 05 18:34:07 2016 +0200
@@ -1,5 +1,5 @@
-/* Copyright 2009-2012 Myhailo Danylenko
+/* Copyright 2009-2016 Myhailo Danylenko
This file is part of mcabber-lua.
@@ -24,9 +24,6 @@
// define this to enable debugging output
#cmakedefine DEBUG
-// define this if you are building with lua 5.2
-#cmakedefine HAVE_LUA52
-
// define this if you want lua to create alias to '/lua' at module loading
#cmakedefine ENABLE_LUA_ALIAS
@@ -39,6 +36,9 @@
// indicates, whether mcabber have built-in carbons completion
#cmakedefine HAVE_COMPL_CARBONS
+// name of module description struct
+#define MODULE_STRUCT info_${LUA_MODULENAME}
+
// size of background pipe reading buffer
#define MLUA_BGREAD_BUFFER ( ${ML_BGREAD_BUFFER} )
@@ -51,10 +51,12 @@
#define OPT_MLUA_RC "${OPT_MLUA_RC}"
#define OPT_MLUA_LM_DEBUG "${OPT_MLUA_LM_DEBUG}"
-#ifndef HAVE_LUA52
+// define if module is building againts lua 5.1
+#cmakedefine LUA51_COMPATIBILITY
+
+#ifdef LUA51_COMPATIBILITY
# define lua_rawlen lua_objlen
# define luaL_setfuncs(STATE, REGTABLE, IGZERO) luaL_register ( STATE, NULL, REGTABLE )
-# define info_lua52 info_lua51
#endif
#ifdef DEBUG
--- a/docs/readme.mdwn Sat Nov 07 22:36:02 2015 +0200
+++ b/docs/readme.mdwn Sat Mar 05 18:34:07 2016 +0200
@@ -1,21 +1,21 @@
# Lua scripting for MCabber
-This module creates lua 5.1 or 5.2 interpreter environment and puts some lua
-functions inside for your code to interact with mcabber.
+This module creates lua 5.1, 5.2 or 5.3 interpreter environment and puts some
+lua functions inside for your code to interact with mcabber.
-Module provides mcabber command `/lua5.1` or `/lua5.2` respectively and adds
-an alias `/lua` for that command. This command evaluates argument as lua code in
-created by module environment.
+Module provides mcabber command `/lua5.1`, `/lua5.2` or `/lua5.3` respectively
+and adds an alias `/lua` for that command. This command evaluates argument as
+lua code in created by module environment.
-Note: If you load both versions - `lua5.1` and `lua5.2`, alias will point to
-which was loaded last.
+Note: If you load multiple versions, alial will point to the one, loaded last.
Lua functions, available in environment are described in api reference, built
-with `docgen` help. It is also available online.
+with `docgen` help. It is also available
+[[online|http://www.isbear.org.ua/docs/mcabber-lua/api/]].
In `examples` dir there are some example scripts, that may be used as is or for
-reference. See also `README` in `examples` dir.
+reference. See also `README` in `examples` dir. They may be outdated, though.
# Installation
@@ -50,10 +50,12 @@
# Building options
-Through `make edit_cache` action you can adjust module parameters. Notably: if
-you set `WANT_LUA52`, module will be built against lua5.2, even if lua5.1 is
-present; you can disable aliasing `lua` command at module loading time by
-unsetting `ENABLE_LUA_ALIAS`; you can adjust mcabber option names to be
+Through `make edit_cache` action you can adjust module parameters. Notably:
+you can specify needed lua version with `WANT_LUA` variable, though you'll
+need to do that from command line at first cache generation
+(-DWANT_LUA=LUAX.X), otherwise cmake will not re-discover lua package; you can
+disable aliasing `lua` command at module loading time by unsetting
+`ENABLE_LUA_ALIAS`; you can adjust mcabber option names to be
version-specific, if you need both versions running simultaneously via
`OPT_MLUA_RC` and `OPT_MLUA_DEBUG`.
@@ -68,5 +70,5 @@
I will 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>
+ -- Myhailo Danylenko <risbea@gmail.com>
--- a/lua.c Sat Nov 07 22:36:02 2015 +0200
+++ b/lua.c Sat Mar 05 18:34:07 2016 +0200
@@ -1,5 +1,5 @@
-/* Copyright 2009-2012 Myhailo Danylenko
+/* Copyright 2009-2016 Myhailo Danylenko
* Copyright 2011 Mikael Berthe
This file is part of mcabber-lua.
@@ -72,7 +72,7 @@
"Command: /" MLUA_COMMAND_NAME )
#endif
-module_info_t info_lua52 = {
+module_info_t MODULE_STRUCT = {
.branch = MCABBER_BRANCH,
.api = MCABBER_API_VERSION,
.version = PROJECT_VERSION,
@@ -1211,7 +1211,7 @@
/// A: integer (interval, seconds), timer function
static int lua_main_timer (lua_State *L)
{
- int interval = luaL_checkint (L, 1);
+ int interval = luaL_checkinteger (L, 1);
guint source;
lua_timer_callback_t *cb;
luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected");