diff --git a/auxdir/x_ac_lua.m4 b/auxdir/x_ac_lua.m4
index a4efdbf8562ca916b5f4fa6f7ce9b55e7d7daa82..d5a7a2b7fc0cb20d8dd5c99421d1180bba02334d 100644
--- a/auxdir/x_ac_lua.m4
+++ b/auxdir/x_ac_lua.m4
@@ -22,9 +22,9 @@ AC_DEFUN([X_AC_LUA],
 
 	if test "x$x_ac_have_lua" = "xyes"; then
 	  saved_CFLAGS="$CFLAGS"
-	  saved_LDFLAGS="$LDFLAGS"
+	  saved_LIBS="$LIBS"
 	  CFLAGS="$CFLAGS $lua_CFLAGS"
-	  LDFLAGS="$LDFLAGS $lua_LIBS"
+	  LIBS="$LIBS $lua_LIBS"
 	  AC_MSG_CHECKING([for whether we can link to liblua])
 	  AC_TRY_LINK(
 		[#include <lua.h>
@@ -37,7 +37,7 @@ AC_DEFUN([X_AC_LUA],
 
 	  AC_MSG_RESULT([$x_ac_have_lua])
 	  CFLAGS="$saved_CFLAGS"
-	  LDFLAGS="$saved_LDFLAGS"
+	  LIBS="$saved_LIBS"
 	fi
 
 	AM_CONDITIONAL(HAVE_LUA, test "x$x_ac_have_lua" = "xyes")