]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Allow to get different types of memory pool variables.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 14 Jul 2015 23:22:03 +0000 (00:22 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 14 Jul 2015 23:22:03 +0000 (00:22 +0100)
src/lua/lua_mempool.c

index 3fe33ade63243618b4d7b3ea470c50a5a7bbc9e0..af19c64b5e6b93aacc1a0f4b8a690f696265bb5c 100644 (file)
@@ -199,11 +199,42 @@ lua_mempool_get_variable (lua_State *L)
 {
        struct memory_pool_s *mempool = rspamd_lua_check_mempool (L, 1);
        const gchar *var = luaL_checkstring (L, 2);
+       const gchar *type = NULL;
        gchar *value;
 
        if (mempool && var) {
                value = rspamd_mempool_get_variable (mempool, var);
+
+               if (lua_gettop (L) >= 3) {
+                       type = luaL_checkstring (L, 3);
+               }
+
                if (value) {
+
+                       if (type) {
+                               if (g_ascii_strcasecmp (type, "double") == 0) {
+                                       lua_pushnumber (L, *(gdouble *)value);
+                               }
+                               else if (g_ascii_strcasecmp (type, "int") == 0) {
+                                       lua_pushnumber (L, *(gint *)value);
+                               }
+                               else if (g_ascii_strcasecmp (type, "int64") == 0) {
+                                       lua_pushnumber (L, *(gint64 *)value);
+                               }
+                               else if (g_ascii_strcasecmp (type, "bool") == 0) {
+                                       lua_pushboolean (L, *(gboolean *)value);
+                               }
+                               else if (g_ascii_strcasecmp (type, "string") == 0) {
+                                       lua_pushstring (L, (const gchar *)value);
+                               }
+                               else {
+                                       msg_err ("unknown type for get_variable: %s", type);
+                                       lua_pushnil (L);
+                               }
+
+                               return 1;
+                       }
+
                        lua_pushstring (L, value);
                }
                else {