]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix various cases in Lua API
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 28 Jun 2019 17:07:11 +0000 (18:07 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 28 Jun 2019 17:07:11 +0000 (18:07 +0100)
src/lua/CMakeLists.txt
src/lua/lua_common.c
src/lua/lua_common.h
src/lua/lua_cryptobox.c

index 4a2003605632ba52421e3fd6cedcf54fba9b3296..2730702b2c880939925221b46cb144030a802ac0 100644 (file)
@@ -29,6 +29,7 @@ SET(LUASRC                      ${CMAKE_CURRENT_SOURCE_DIR}/lua_common.c
                                          ${CMAKE_CURRENT_SOURCE_DIR}/lua_dns.c
                                          ${CMAKE_CURRENT_SOURCE_DIR}/lua_udp.c
                                          ${CMAKE_CURRENT_SOURCE_DIR}/lua_text.c
-                                         ${CMAKE_CURRENT_SOURCE_DIR}/lua_worker.c)
+                                         ${CMAKE_CURRENT_SOURCE_DIR}/lua_worker.c
+                                         ${CMAKE_CURRENT_SOURCE_DIR}/lua_kann.c)
 
 SET(RSPAMD_LUA ${LUASRC} PARENT_SCOPE)
\ No newline at end of file
index a33f3379164236415c9e2a0d16292e34a85e472c..785042b8e74a5181dd987f1990c92af8c2480e23 100644 (file)
@@ -47,7 +47,7 @@ lua_error_quark (void)
 
 /* Util functions */
 /**
- * Create new class and store metatable on top of the stack
+ * Create new class and store metatable on top of the stack (must be popped if not needed)
  * @param L
  * @param classname name of class
  * @param func table of class methods
@@ -62,10 +62,14 @@ rspamd_lua_new_class (lua_State * L,
        lua_pushvalue (L, -2);      /* pushes the metatable */
        lua_settable (L, -3);       /* metatable.__index = metatable */
 
-       lua_pushstring (L, "class");    /* mt,"__index",it,"class" */
-       lua_pushstring (L, classname);  /* mt,"__index",it,"class",classname */
-       lua_rawset (L, -3);         /* mt,"__index",it */
-       luaL_register (L, NULL, methods);
+       lua_pushstring (L, "class");    /* mt,"class" */
+       lua_pushstring (L, classname);  /* mt,"class",classname */
+       lua_rawset (L, -3);         /* mt */
+
+       if (methods) {
+               luaL_register (L, NULL, methods); /* pushes all methods as MT fields */
+       }
+       /* MT is left on stack ! */
 }
 
 /**
@@ -915,6 +919,7 @@ rspamd_lua_init (bool wipe_mem)
        luaopen_dns (L);
        luaopen_udp (L);
        luaopen_worker (L);
+       luaopen_kann (L);
 
        luaL_newmetatable (L, "rspamd{ev_base}");
        lua_pushstring (L, "class");
index 8919a46fdb1a354643f022c06a805431900f8861..4c0605782982176669bf4ce1b1ddf1ddfaa1d27c 100644 (file)
@@ -42,9 +42,9 @@ luaL_register (lua_State *L, const gchar *name, const struct luaL_reg *methods)
 #endif
 
 /* Interface definitions */
-#define LUA_FUNCTION_DEF(class, name) static gint lua_ ## class ## _ ## name ( \
+#define LUA_FUNCTION_DEF(class, name) static int lua_ ## class ## _ ## name ( \
                lua_State * L)
-#define LUA_PUBLIC_FUNCTION_DEF(class, name) gint lua_ ## class ## _ ## name ( \
+#define LUA_PUBLIC_FUNCTION_DEF(class, name) int lua_ ## class ## _ ## name ( \
                lua_State * L)
 #define LUA_INTERFACE_DEF(class, name) { # name, lua_ ## class ## _ ## name }
 
@@ -286,6 +286,7 @@ void luaopen_cryptobox (lua_State *L);
 void luaopen_dns (lua_State *L);
 void luaopen_udp (lua_State * L);
 void luaopen_worker (lua_State * L);
+void luaopen_kann (lua_State * L);
 
 void rspamd_lua_dostring (const gchar *line);
 
index 300c33793b4e199ee5bb5acdd76bc7d980f2f8a4..63608ed9addfdb851b185dfd59ae52ca3d83f062 100644 (file)
@@ -1075,8 +1075,8 @@ lua_cryptobox_hash_create (lua_State *L)
 /***
  * @function rspamd_cryptobox_hash.create_specific(type, [string])
  * Creates new hash context
- * @param {string} type type of signature
- * @param {string} data raw signature data
+ * @param {string} type type of hash (blake2, sha256, md5, sha512, mum, xxh64, xxh32, t1ha)
+ * @param {string} string initial data
  * @return {cryptobox_hash} hash object
  */
 static gint