From 839e4775b77c3b1fe256c640ab9920ebb6e51afb Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 5 May 2016 09:26:43 +0100 Subject: [PATCH] [Feature] Improve logging lua types --- src/lua/lua_common.h | 11 +++++++++++ src/lua/lua_logger.c | 11 +++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index c20d833ca3..73be9e0c51 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -335,5 +335,16 @@ void lua_push_internet_address_list (lua_State *L, InternetAddressList *addrs); * @return */ gboolean lua_push_internet_address (lua_State *L, InternetAddress *ia); + +/** + * Log lua object to string + * @param L + * @param pos + * @param outbuf + * @param len + * @return + */ +gsize lua_logger_out_type (lua_State *L, gint pos, gchar *outbuf, + gsize len); #endif /* WITH_LUA */ #endif /* RSPAMD_LUA_H */ diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c index 125f0ff80e..462838ba1f 100644 --- a/src/lua/lua_logger.c +++ b/src/lua/lua_logger.c @@ -55,9 +55,6 @@ print(str) -- Output: a=string, b=1.50000, c=1, d={[1] = aa, [2] = 1, [3] = bb} e={[key]=value, [key2]=1.0} */ -static gsize lua_logger_out_type (lua_State *L, gint pos, gchar *outbuf, - gsize len); - /* Logger methods */ /*** * @function logger.err(msg) @@ -404,7 +401,7 @@ lua_logger_out_table (lua_State *L, gint pos, gchar *outbuf, gsize len) #undef MOVE_BUF -static gsize +gsize lua_logger_out_type (lua_State *L, gint pos, gchar *outbuf, gsize len) { gint type; @@ -432,6 +429,12 @@ lua_logger_out_type (lua_State *L, gint pos, gchar *outbuf, gsize len) case LUA_TFUNCTION: r = rspamd_snprintf (outbuf, len + 1, "function"); break; + case LUA_TNIL: + r = rspamd_snprintf (outbuf, len + 1, "nil"); + break; + case LUA_TNONE: + r = rspamd_snprintf (outbuf, len + 1, "no value"); + break; default: /* Try to push everything as string using tostring magic */ r = lua_logger_out_str (L, pos, outbuf, len); -- 2.47.3