summaryrefslogtreecommitdiffstats
path: root/bin/lem.c
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 /bin/lem.c
parent17f161df169a77670a25f739771d4ac6d22920c6 (diff)
downloadlem-90ce005742046d16f0ca59869b5a5ae99934b96b.tar.gz
lem-90ce005742046d16f0ca59869b5a5ae99934b96b.tar.xz
lem-90ce005742046d16f0ca59869b5a5ae99934b96b.zip
lem: unbreak build against plain Lua 5.1
Diffstat (limited to 'bin/lem.c')
-rw-r--r--bin/lem.c20
1 files changed, 20 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