diff --git a/configure b/configure
index 98fb6cdbfbf3b1b523b628f8514658cd8df4e9fd..ec7d1555db291484adaeb5572910282c53466ad8 100755
--- a/configure
+++ b/configure
@@ -1051,6 +1051,7 @@ PBX_MISDN
 MISDN_DIR
 MISDN_INCLUDE
 MISDN_LIB
+LUA_VERSIONS
 PBX_LUA
 LUA_DIR
 LUA_INCLUDE
@@ -1477,6 +1478,7 @@ CCC
 CXXCPP
 JANSSON_CONFIGURE_OPTS
 PJPROJECT_CONFIGURE_OPTS
+LUA_VERSIONS
 PKG_CONFIG
 PKG_CONFIG_PATH
 PKG_CONFIG_LIBDIR
@@ -2235,6 +2237,8 @@ Some influential environment variables:
               Additional configure options to pass to bundled jansson
   PJPROJECT_CONFIGURE_OPTS
               Additional configure options to pass to bundled pjproject
+  LUA_VERSIONS
+              A space separated list of target lua versions to test.
   PKG_CONFIG  path to pkg-config utility
   PKG_CONFIG_PATH
               directories to add to pkg-config's search path
@@ -29633,7 +29637,7 @@ fi
 
 
 
-for ver in 5.4 5.3 5.2 5.1; do
+for ver in ${LUA_VERSIONS:-5.4 5.3 5.2 5.1}; do
 
 if test "x${PBX_LUA}" != "x1" -a "${USE_LUA}" != "no"; then
    pbxlibdir=""
@@ -29744,6 +29748,7 @@ fi
 done
 
 # Some distributions (like openSUSE and NetBSD) remove the 5.x suffix.
+if test "x${LUA_VERSIONS}" = "x"; then
 
 if test "x${PBX_LUA}" != "x1" -a "${USE_LUA}" != "no"; then
    pbxlibdir=""
@@ -29840,6 +29845,7 @@ _ACEOF
 fi
 
 
+fi
 
 # Accept either RADIUS client library, their APIs are fully compatible,
 # just different header filenames and different SONAMEs
diff --git a/configure.ac b/configure.ac
index e842a0c087483fe0d7dd9b7670f41d1d71ad4280..c34638a248bbeeae6c7b4b4bdb6d9fb0d6e058be 100644
--- a/configure.ac
+++ b/configure.ac
@@ -511,6 +511,7 @@ AST_EXT_LIB_SETUP([LIBXML2], [LibXML2], [libxml2])
 AST_EXT_LIB_SETUP([LIBXSLT], [LibXSLT], [libxslt])
 AST_EXT_LIB_SETUP_OPTIONAL([LIBXSLT_CLEANUP], [LibXSLT Library Cleanup Function], [LIBXSLT], [libxslt])
 AST_EXT_LIB_SETUP([LUA], [Lua], [lua])
+AC_ARG_VAR([LUA_VERSIONS],[A space separated list of target lua versions to test.])
 AST_EXT_LIB_SETUP([MISDN], [mISDN user], [misdn])
 AST_EXT_LIB_SETUP([MYSQLCLIENT], [MySQL client], [mysqlclient])
 AST_EXT_LIB_SETUP([NBS], [Network Broadcast Sound], [nbs])
@@ -2559,7 +2560,7 @@ if test -z "$__opus_include" -o x"$__opus_include" = x" " ; then
 fi
 AST_EXT_LIB_CHECK([OPUSFILE], [opusfile], [op_open_callbacks], [opus/opusfile.h], [], [$__opus_include])
 
-for ver in 5.4 5.3 5.2 5.1; do
+for ver in ${LUA_VERSIONS:-5.4 5.3 5.2 5.1}; do
 	AST_EXT_LIB_CHECK([LUA], lua${ver}, [luaL_newstate], lua${ver}/lua.h, [-lm])
 	if test "x${PBX_LUA}" = "x1" ; then
 		if test x"${LUA_DIR}" = x; then
@@ -2572,7 +2573,9 @@ for ver in 5.4 5.3 5.2 5.1; do
 done
 
 # Some distributions (like openSUSE and NetBSD) remove the 5.x suffix.
-AST_EXT_LIB_CHECK([LUA], [lua], [luaL_newstate], [lua.h], [-lm])
+if test "x${LUA_VERSIONS}" = "x"; then
+	AST_EXT_LIB_CHECK([LUA], [lua], [luaL_newstate], [lua.h], [-lm])
+fi
 
 # Accept either RADIUS client library, their APIs are fully compatible,
 # just different header filenames and different SONAMEs