commit c02521c: [Minor] Lua_task: Add topointer method

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Feb 8 17:49:06 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-02-08 17:06:03 +0000
URL: https://github.com/rspamd/rspamd/commit/c02521c917656a056f7786493d632bf10cce3791

[Minor] Lua_task: Add topointer method

---
 src/libserver/dkim.h |  2 --
 src/lua/lua_task.c   | 24 ++++++++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/libserver/dkim.h b/src/libserver/dkim.h
index d57c923bb..fe2b4cc4e 100644
--- a/src/libserver/dkim.h
+++ b/src/libserver/dkim.h
@@ -101,8 +101,6 @@ typedef struct rspamd_dkim_sign_context_s rspamd_dkim_sign_context_t;
 
 struct rspamd_dkim_key_s;
 typedef struct rspamd_dkim_key_s rspamd_dkim_key_t;
-
-struct rspamd_dkim_key_s;
 typedef struct rspamd_dkim_key_s rspamd_dkim_sign_key_t;
 
 struct rspamd_task;
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index c4e1b6d92..90cb1f689 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -986,6 +986,13 @@ LUA_FUNCTION_DEF (task, get_stat_tokens);
  */
 LUA_FUNCTION_DEF (task, lookup_words);
 
+/**
+ * @method task:topointer()
+ *
+ * Returns raw C pointer (lightuserdata) associated with task
+ */
+LUA_FUNCTION_DEF (task, topointer);
+
 static const struct luaL_reg tasklib_f[] = {
 	LUA_INTERFACE_DEF (task, load_from_file),
 	LUA_INTERFACE_DEF (task, load_from_string),
@@ -1091,6 +1098,7 @@ static const struct luaL_reg tasklib_m[] = {
 	LUA_INTERFACE_DEF (task, get_stat_tokens),
 	LUA_INTERFACE_DEF (task, get_meta_words),
 	LUA_INTERFACE_DEF (task, lookup_words),
+	LUA_INTERFACE_DEF (task, topointer),
 	{"__tostring", rspamd_lua_class_tostring},
 	{NULL, NULL}
 };
@@ -5434,6 +5442,22 @@ lua_task_lookup_words (lua_State *L)
 	return 1;
 }
 
+static gint
+lua_task_topointer (lua_State *L)
+{
+	LUA_TRACE_POINT;
+	struct rspamd_task *task = lua_check_task (L, 1);
+
+	if (task) {
+		lua_pushlightuserdata (L, task);
+	}
+	else {
+		return luaL_error (L, "invalid arguments");
+	}
+
+	return 1;
+}
+
 
 /* Image functions */
 static gint


More information about the Commits mailing list