Index: src/mod_magnet.c =================================================================== --- src/mod_magnet.c (.../tags/lighttpd-1.4.24) +++ src/mod_magnet.c (.../branches/lighttpd-1.4.x) @@ -170,6 +170,7 @@ return lua_gettop(L); } else { lua_pushvalue(L, lua_upvalueindex(1)); + lua_insert(L, 1); lua_call(L, lua_gettop(L) - 1, LUA_MULTRET); return lua_gettop(L); } @@ -824,9 +825,36 @@ 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 */ @@ -955,7 +983,9 @@ 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():", @@ -969,6 +999,7 @@ 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); Index: configure.ac =================================================================== Index: SConstruct =================================================================== Index: NEWS =================================================================== --- NEWS (.../tags/lighttpd-1.4.24) +++ NEWS (.../branches/lighttpd-1.4.x) @@ -3,7 +3,11 @@ NEWS ==== -- 1.4.24 - +- 1.4.25 - + * mod_magnet: fix pairs() for normal tables and strings (fixes #1307) + * mod_magnet: add traceback for printing lua errors + +- 1.4.24 - 2009-10-25 * Add T_CONFIG_INT for bigger integers from the config (needed for #1966) * Use unsigned int (and T_CONFIG_INT) for max_request_size * Use unsigned int for secdownload.timeout (fixes #1966) Index: CMakeLists.txt ===================================================================