Build system, lua plugin: Update for Lua 5.1
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 25 Nov 2010 11:36:33 +0000 (12:36 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 25 Nov 2010 11:36:33 +0000 (12:36 +0100)
I realized I used Lua 5.0 which has been superseeded by Lua 5.1 in 2006.

The build system now uses pkg-config to check for Lua 5.1. Minor
adjustments had to be made to the plugin to work with the new version.

configure.in
src/lua.c

index 146fe5c..3610f26 100644 (file)
@@ -1967,78 +1967,48 @@ AM_CONDITIONAL(BUILD_WITH_JAVA, test "x$with_java" = "xyes")
 # }}}
 
 # --with-liblua {{{
-with_liblua_config="lua-config50"
 with_liblua_cppflags=""
 with_liblua_ldflags=""
 with_liblua_libs=""
-AC_ARG_WITH(liblua, [AS_HELP_STRING([--with-liblua@<:@=lua-config50@:>@], [Path to the Lua config script.])],
-[
-    if test "x$withval" = "xno" || test "x$withval" = "xyes"
-    then
-           with_liblua="$withval"
-    else
-           if test -f "$withval" && test -x "$withval"
-           then
-                   with_liblua_config="$withval"
-                   with_liblua="yes"
-           else if test -x "$withval/bin/lua-config50"
-           then
-                   with_liblua_config="$withval/bin/lua-config50"
-                   with_liblua="yes"
-           else
-                   AC_MSG_ERROR("not an executable: $withval")
-           fi; fi
-    fi
-],
-[
-    with_liblua="yes"
-])
+with_liblua="yes"
+
 if test "x$with_liblua" = "xyes"
 then
-       with_liblua_cppflags=`$with_liblua_config --include 2>/dev/null`
+       $PKG_CONFIG --exists lua5.1 2>/dev/null
        lua_config_status=$?
 
-       if test $lua_config_status -ne 0
+       if test 0 -ne $lua_config_status
        then
-               with_liblua="no ($with_liblua_config failed)"
-       else
-               SAVE_CPPFLAGS="$CPPFLAGS"
-               CPPFLAGS="$CPPFLAGS $with_liblua_cppflags"
-
-               AC_CHECK_HEADERS(lua.h, [], [with_liblua="no (lua.h not found)"], [])
-
-               CPPFLAGS="$SAVE_CPPFLAGS"
+               with_liblua="no"
        fi
 fi
+
 if test "x$with_liblua" = "xyes"
 then
-       with_liblua_ldflags=`$with_liblua_config --libs-only-L 2>/dev/null`
-       lua_config_status=$?
-
-       if test $lua_config_status -ne 0
-       then
-               with_liblua="no ($with_liblua_config failed)"
-       fi
+       with_liblua_cppflags=`$PKG_CONFIG --cflags-only-I lua5.1` || with_liblua="no"
+       with_liblua_ldflags=`$PKG_CONFIG --libs-only-L lua5.1` || with_liblua="no"
+       with_liblua_libs=`$PKG_CONFIG --libs-only-l lua5.1` || with_liblua="no"
 fi
 if test "x$with_liblua" = "xyes"
 then
-       with_liblua_libs=`$with_liblua_config --libs-only-l 2>/dev/null`
-       lua_config_status=$?
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_liblua_cppflags"
 
-       if test $lua_config_status -ne 0
-       then
-               with_liblua="no ($with_liblua_config failed)"
-       else
-               SAVE_LDFLAGS="$LDFLAGS"
-               SAVE_LIBS="$LIBS"
-               LDFLAGS="$SAVE_LDFLAGS $with_liblua_ldflags"
-               LIBS="$LIBS $with_liblua_libs"
+       AC_CHECK_HEADERS(lua.h lauxlib.h lualib.h, [], [with_liblua="no (header not found)"], [])
 
-               AC_CHECK_FUNC(lua_settop, [with_liblua="yes"], [with_liblua="no (symbol 'lua_settop' not found)"])
+       CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+if test "x$with_liblua" = "xyes"
+then
+       SAVE_LDFLAGS="$LDFLAGS"
+       SAVE_LIBS="$LIBS"
+       LDFLAGS="$SAVE_LDFLAGS $with_liblua_ldflags"
+       LIBS="$LIBS $with_liblua_libs"
 
-               LDFLAGS="$SAVE_LDFLAGS"
-               LIBS="$SAVE_LIBS"
-       fi
+       AC_CHECK_FUNC(lua_settop, [with_liblua="yes"], [with_liblua="no (symbol 'lua_settop' not found)"])
+
+       LDFLAGS="$SAVE_LDFLAGS"
+       LIBS="$SAVE_LIBS"
 fi
 if test "x$with_liblua" = "xyes"
 then
index b79e0b1..4ea5da7 100644 (file)
--- a/src/lua.c
+++ b/src/lua.c
  *   Florian Forster <octo at collectd.org>
  **/
 
+/* <lua5.1/luaconf.h> defines a macro using "sprintf". Although not used here,
+ * GCC will complain about the macro definition. */
+#define DONT_POISON_SPRINTF_YET
+
 #include "collectd.h"
 #include "plugin.h"
 #include "common.h"
 #include <lauxlib.h>
 #include <lualib.h>
 
+#if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
+# undef sprintf
+# pragma GCC poison sprintf
+#endif
+
 typedef struct lua_script_s {
   char          *script_path;
   lua_State     *lua_state;
@@ -322,7 +331,7 @@ static int lua_script_load (const char *script_path) /* {{{ */
     return (-1);
   }
 
-  status = lua_dofile (script->lua_state, script->script_path);
+  status = luaL_dofile (script->lua_state, script->script_path);
   if (status != 0)
   {
     const char *errmsg;