aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_mempool.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-15 00:22:03 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-15 00:22:03 +0100
commitf999cd8e8b6689ea73ba1b6d9a54ae63dde1aa86 (patch)
tree0b5a335deb07604be5b01c4eef3e733c589a0568 /src/lua/lua_mempool.c
parent96f05a55a63ec28f423e204d8e66a94c9f605e61 (diff)
downloadrspamd-f999cd8e8b6689ea73ba1b6d9a54ae63dde1aa86.tar.gz
rspamd-f999cd8e8b6689ea73ba1b6d9a54ae63dde1aa86.zip
Allow to get different types of memory pool variables.
Diffstat (limited to 'src/lua/lua_mempool.c')
-rw-r--r--src/lua/lua_mempool.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c
index 3fe33ade6..af19c64b5 100644
--- a/src/lua/lua_mempool.c
+++ b/src/lua/lua_mempool.c
@@ -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 {