summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Renner Berthing <esmil@mailme.dk>2013-01-17 14:53:43 +0100
committerEmil Renner Berthing <esmil@mailme.dk>2013-01-17 15:15:16 +0100
commit90ce005742046d16f0ca59869b5a5ae99934b96b (patch)
tree9fce4daf10197c97e500003707636297cba1820c
parent17f161df169a77670a25f739771d4ac6d22920c6 (diff)
downloadlem-90ce005742046d16f0ca59869b5a5ae99934b96b.tar.gz
lem-90ce005742046d16f0ca59869b5a5ae99934b96b.tar.xz
lem-90ce005742046d16f0ca59869b5a5ae99934b96b.zip
lem: unbreak build against plain Lua 5.1
-rw-r--r--bin/lem.c20
-rwxr-xr-xconfigure6
-rw-r--r--configure.ac2
3 files changed, 28 insertions, 0 deletions
diff --git a/bin/lem.c b/bin/lem.c
index 17bc15f..67789f5 100644
--- a/bin/lem.c
+++ b/bin/lem.c
@@ -195,10 +195,30 @@ lem_queue(lua_State *T, int nargs)
static void
thread_error(lua_State *T)
{
+#ifdef HAVE_TRACEBACK
const char *msg = lua_tostring(T, -1);
if (msg)
luaL_traceback(L, T, msg, 0);
+#else /* adapted from Lua 5.1 source */
+ if (!lua_isstring(T, -1)) /* 'message' not a string? */
+ return;
+ lua_getfield(T, LUA_GLOBALSINDEX, "debug");
+ if (!lua_istable(T, -1)) {
+ lua_pop(T, 1);
+ goto merror;
+ }
+ lua_getfield(T, -1, "traceback");
+ if (!lua_isfunction(T, -1)) {
+ lua_pop(T, 2);
+ goto merror;
+ }
+ lua_pushvalue(T, -3); /* pass error message */
+ lua_pushinteger(T, 1); /* skip traceback */
+ lua_call(T, 2, 1); /* call debug.traceback */
+merror:
+ lua_xmove(T, L, 1); /* move error message to L */
+#endif
}
static void
diff --git a/configure b/configure
index 6128b6a..42086db 100755
--- a/configure
+++ b/configure
@@ -5262,6 +5262,12 @@ if test "x$cmoddir" = 'x'; then :
as_fn_error $? "unable to deduce Lua C module directory, please use --with-cmoddir=path" "$LINENO" 5
fi
+ac_fn_c_check_func "$LINENO" "luaL_traceback" "ac_cv_func_luaL_traceback"
+if test "x$ac_cv_func_luaL_traceback" = xyes; then :
+ CPPFLAGS="$CPPFLAGS -DHAVE_TRACEBACK"
+fi
+
+
# Checks for header files.
for ac_header in stddef.h stdlib.h string.h unistd.h sys/time.h time.h pthread.h
do :
diff --git a/configure.ac b/configure.ac
index 1e7fc76..5ef6743 100644
--- a/configure.ac
+++ b/configure.ac
@@ -92,6 +92,8 @@ AS_IF([test "x$lmoddir" = 'x'],
AS_IF([test "x$cmoddir" = 'x'],
[AC_MSG_ERROR([unable to deduce Lua C module directory, please use --with-cmoddir=path])])
+AC_CHECK_FUNC([luaL_traceback], [CPPFLAGS="$CPPFLAGS -DHAVE_TRACEBACK"])
+
# Checks for header files.
AC_CHECK_HEADERS([stddef.h stdlib.h string.h unistd.h sys/time.h time.h pthread.h])
AC_CHECK_HEADERS([sys/eventfd.h sys/epoll.h sys/event.h])