aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_logger.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-04 15:46:25 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-04 15:46:25 +0100
commitdb51a9071af9587cf152937cb900e663b424a7e7 (patch)
treec3168571ef755b30fab83469dddf2bd79d27d8a1 /src/lua/lua_logger.c
parent4bdef6885b5ff5f86b52c074c9a9d453a68d6fc0 (diff)
downloadrspamd-db51a9071af9587cf152937cb900e663b424a7e7.tar.gz
rspamd-db51a9071af9587cf152937cb900e663b424a7e7.zip
[Feature] Print userdata using tostring if possible
Diffstat (limited to 'src/lua/lua_logger.c')
-rw-r--r--src/lua/lua_logger.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c
index 66c472a27..125f0ff80 100644
--- a/src/lua/lua_logger.c
+++ b/src/lua/lua_logger.c
@@ -283,6 +283,7 @@ static gsize
lua_logger_out_userdata (lua_State *L, gint pos, gchar *outbuf, gsize len)
{
gint r;
+ const gchar *str = NULL;
if (!lua_getmetatable (L, pos)) {
return 0;
@@ -296,16 +297,32 @@ lua_logger_out_userdata (lua_State *L, gint pos, gchar *outbuf, gsize len)
return 0;
}
- lua_pushstring (L, "class");
+ lua_pushstring (L, "__tostring");
lua_gettable (L, -2);
- if (!lua_isstring (L, -1)) {
- lua_pop (L, 3);
- return 0;
+ if (lua_isfunction (L, -1)) {
+ lua_pushvalue (L, pos);
+
+ if (lua_pcall (L, 1, 1, 0) != 0) {
+ lua_pop (L, 3);
+ return 0;
+ }
+
+ str = lua_tostring (L, -1);
+ }
+ else {
+ lua_pushstring (L, "class");
+ lua_gettable (L, -2);
+
+ if (!lua_isstring (L, -1)) {
+ lua_pop (L, 3);
+ return 0;
+ }
+
+ str = lua_tostring (L, -1);
}
- r = rspamd_snprintf (outbuf, len + 1, "%s(%p)", lua_tostring (L, -1),
- lua_touserdata (L, pos));
+ r = rspamd_snprintf (outbuf, len + 1, "%s(%p)", str, lua_touserdata (L, pos));
lua_pop (L, 3);
return r;