]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
pbx_lua: Add support for Lua 5.2
authorKinsey Moore <kmoore@digium.com>
Wed, 8 Jan 2014 16:17:32 +0000 (16:17 +0000)
committerKinsey Moore <kmoore@digium.com>
Wed, 8 Jan 2014 16:17:32 +0000 (16:17 +0000)
This adds support for Lua 5.2 in pbx_lua which is available on newer
operating systems.

(closes issue ASTERISK-23011)
Review: https://reviewboard.asterisk.org/r/3075/
Reported by: George Joseph
Patch by: George Joseph
........

Merged revisions 405090 from http://svn.asterisk.org/svn/asterisk/branches/1.8

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@405091 65c4cc65-6c06-0410-ace0-fbb531ad65f3

configure
configure.ac
pbx/pbx_lua.c

index c5a74f1202aa03c13a7c334198461e80a84e05b3..f606fe3351e0f8601dbb530a87fd578dbad32857 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 400075 .
+# From configure.ac Revision: 400768 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.69 for asterisk trunk.
 #
@@ -26319,6 +26319,118 @@ $as_echo "#define HAVE_OPENH323 1" >>confdefs.h
 fi
 
 
+if test "x${PBX_LUA}" != "x1" -a "${USE_LUA}" != "no"; then
+   pbxlibdir=""
+   # if --with-LUA=DIR has been specified, use it.
+   if test "x${LUA_DIR}" != "x"; then
+      if test -d ${LUA_DIR}/lib; then
+         pbxlibdir="-L${LUA_DIR}/lib"
+      else
+         pbxlibdir="-L${LUA_DIR}"
+      fi
+   fi
+   pbxfuncname="luaL_newstate"
+   if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
+      AST_LUA_FOUND=yes
+   else
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} "
+      as_ac_Lib=`$as_echo "ac_cv_lib_lua5.2_${pbxfuncname}" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${pbxfuncname} in -llua5.2" >&5
+$as_echo_n "checking for ${pbxfuncname} in -llua5.2... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-llua5.2 ${pbxlibdir} -lm $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ${pbxfuncname} ();
+int
+main ()
+{
+return ${pbxfuncname} ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval "$as_ac_Lib=yes"
+else
+  eval "$as_ac_Lib=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+eval ac_res=\$$as_ac_Lib
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
+  AST_LUA_FOUND=yes
+else
+  AST_LUA_FOUND=no
+fi
+
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+   fi
+
+   # now check for the header.
+   if test "${AST_LUA_FOUND}" = "yes"; then
+      LUA_LIB="${pbxlibdir} -llua5.2 -lm"
+      # if --with-LUA=DIR has been specified, use it.
+      if test "x${LUA_DIR}" != "x"; then
+         LUA_INCLUDE="-I${LUA_DIR}/include"
+      fi
+      LUA_INCLUDE="${LUA_INCLUDE} "
+      if test "xlua5.2/lua.h" = "x" ; then     # no header, assume found
+         LUA_HEADER_FOUND="1"
+      else                             # check for the header
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${LUA_INCLUDE}"
+         ac_fn_c_check_header_mongrel "$LINENO" "lua5.2/lua.h" "ac_cv_header_lua5_2_lua_h" "$ac_includes_default"
+if test "x$ac_cv_header_lua5_2_lua_h" = xyes; then :
+  LUA_HEADER_FOUND=1
+else
+  LUA_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+      fi
+      if test "x${LUA_HEADER_FOUND}" = "x0" ; then
+         LUA_LIB=""
+         LUA_INCLUDE=""
+      else
+         if test "x${pbxfuncname}" = "x" ; then                # only checking headers -> no library
+            LUA_LIB=""
+         fi
+         PBX_LUA=1
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_LUA 1
+_ACEOF
+
+      fi
+   fi
+fi
+
+
+if test "x${PBX_LUA}" = "x1" ; then
+       if test x"${LUA_DIR}" = x; then
+               LUA_INCLUDE="${LUA_INCLUDE} -I/usr/include/lua5.2"
+       else
+               LUA_INCLUDE="${LUA_INCLUDE} -I${LUA_DIR}/lua5.2"
+       fi
+fi
+
+
 if test "x${PBX_LUA}" != "x1" -a "${USE_LUA}" != "no"; then
    pbxlibdir=""
    # if --with-LUA=DIR has been specified, use it.
@@ -26442,7 +26554,7 @@ if test "x${PBX_LUA}" != "x1" -a "${USE_LUA}" != "no"; then
          pbxlibdir="-L${LUA_DIR}"
       fi
    fi
-   pbxfuncname="luaL_register"
+   pbxfuncname="luaL_openlib"
    if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
       AST_LUA_FOUND=yes
    else
index 916e504906da00326af15d32de8160ece0cd84ad..5d700cd9054c3ed03b26fbc267f72fb7d6cceaa6 100644 (file)
@@ -2093,6 +2093,15 @@ if test "${PBX_PWLIB}" = "1" -a "${USE_OPENH323}" != "no" ; then
                [${PWLIB_INCLUDE}], [${PWLIB_LIB}])
 fi
 
+AST_EXT_LIB_CHECK([LUA], [lua5.2], [luaL_newstate], [lua5.2/lua.h], [-lm])
+if test "x${PBX_LUA}" = "x1" ; then
+       if test x"${LUA_DIR}" = x; then
+               LUA_INCLUDE="${LUA_INCLUDE} -I/usr/include/lua5.2"
+       else
+               LUA_INCLUDE="${LUA_INCLUDE} -I${LUA_DIR}/lua5.2"
+       fi
+fi
+
 AST_EXT_LIB_CHECK([LUA], [lua5.1], [luaL_newstate], [lua5.1/lua.h], [-lm])
 if test "x${PBX_LUA}" = "x1" ; then
        if test x"${LUA_DIR}" = x; then
@@ -2103,7 +2112,7 @@ if test "x${PBX_LUA}" = "x1" ; then
 fi
 
 # Some distributions (like SuSE) remove the 5.1 suffix.
-AST_EXT_LIB_CHECK([LUA], [lua], [luaL_register], [lua.h], [-lm])
+AST_EXT_LIB_CHECK([LUA], [lua], [luaL_openlib], [lua.h], [-lm])
 
 AST_EXT_LIB_CHECK([RADIUS], [radiusclient-ng], [rc_read_config], [radiusclient-ng.h])
 
index 1b918279450531b8e159532c1e3562fd0558c169..3a33325a3bc1a66ed1e725584cd5930a2dccba21 100644 (file)
@@ -873,8 +873,11 @@ static int lua_sort_extensions(lua_State *L)
                 * table in the extensions_order table */
                for (lua_pushnil(L); lua_next(L, context); lua_pop(L, 1)) {
                        int exten = lua_gettop(L) - 1;
-
+#if LUA_VERSION_NUM < 502
                        lua_pushinteger(L, lua_objlen(L, context_order) + 1);
+#else
+                       lua_pushinteger(L, lua_rawlen(L, context_order) + 1);
+#endif
                        lua_pushvalue(L, exten);
                        lua_settable(L, context_order);
                }
@@ -1506,9 +1509,13 @@ static int lua_find_extension(lua_State *L, const char *context, const char *ext
        lua_remove(L, -2);  /* remove the extensions order table */
 
        context_order_table = lua_gettop(L);
-       
+
        /* step through the extensions looking for a match */
+#if LUA_VERSION_NUM < 502
        for (i = 1; i < lua_objlen(L, context_order_table) + 1; i++) {
+#else
+       for (i = 1; i < lua_rawlen(L, context_order_table) + 1; i++) {
+#endif
                int e_index_copy, match = 0;
                const char *e;