summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstbuehler <stbuehler@152afb58-edef-0310-8abb-c4023f1b3aa9>2009-10-26 15:12:18 +0000
committerstbuehler <stbuehler@152afb58-edef-0310-8abb-c4023f1b3aa9>2009-10-26 15:12:18 +0000
commitc603cba2c23c7a7ef2afba6dabed3c049827c905 (patch)
tree5d5d9e56634925f0f13c77e51c52801ff47290e6
parent24329894797d30e80deadb88e442155f31727584 (diff)
downloadlighttpd-c603cba2c23c7a7ef2afba6dabed3c049827c905.tar.gz
mod_magnet: add traceback for printing lua errors
git-svn-id: svn://svn.lighttpd.net/lighttpd/trunk@2682 152afb58-edef-0310-8abb-c4023f1b3aa9
-rw-r--r--NEWS1
-rw-r--r--src/mod_magnet.c32
2 files changed, 32 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 06d25926..afc46534 100644
--- a/NEWS
+++ b/NEWS
@@ -152,6 +152,7 @@ NEWS
* Fix mod_cgi hang on "crash-before-header-sent" bug
* Set content-length in mod_compress (fixes #2089, thx liming)
* Mark recv-queue closed if backend connection got closed in mod_proxy_core (fixes #2090, thx liming)
+ * mod_magnet: add traceback for printing lua errors
- 1.5.0-r19.. -
* -F option added for spawn-fcgi
diff --git a/src/mod_magnet.c b/src/mod_magnet.c
index 48b33f00..d1260396 100644
--- a/src/mod_magnet.c
+++ b/src/mod_magnet.c
@@ -695,9 +695,36 @@ static int magnet_attach_content(server *srv, connection *con, plugin_data *p, l
return 0;
}
+static int traceback (lua_State *L) {
+ if (!lua_isstring(L, 1)) /* 'message' not a string? */
+ return 1; /* keep it intact */
+ lua_getfield(L, LUA_GLOBALSINDEX, "debug");
+ if (!lua_istable(L, -1)) {
+ lua_pop(L, 1);
+ return 1;
+ }
+ lua_getfield(L, -1, "traceback");
+ if (!lua_isfunction(L, -1)) {
+ lua_pop(L, 2);
+ return 1;
+ }
+ lua_pushvalue(L, 1); /* pass error message */
+ lua_pushinteger(L, 2); /* skip this function and traceback */
+ lua_call(L, 2, 1); /* call debug.traceback */
+ return 1;
+}
+
+static int push_traceback(lua_State *L, int narg) {
+ int base = lua_gettop(L) - narg; /* function index */
+ lua_pushcfunction(L, traceback);
+ lua_insert(L, base);
+ return base;
+}
+
static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, buffer *name) {
lua_State *L;
int lua_return_value = -1;
+ int errfunc;
/* get the script-context */
@@ -812,7 +839,9 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu
lua_setfenv(L, -2); /* on the stack should be a modified env (sp -= 1) */
- if (lua_pcall(L, 0, 1, 0)) {
+ errfunc = push_traceback(L, 0);
+ if (lua_pcall(L, 0, 1, errfunc)) {
+ lua_remove(L, errfunc);
log_error_write(srv, __FILE__, __LINE__,
"ss",
"lua_pcall():",
@@ -825,6 +854,7 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu
return HANDLER_FINISHED;
}
+ lua_remove(L, errfunc);
/* we should have the function-copy and the return value on the stack */
assert(lua_gettop(L) == 2);