]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add some missing types and docs to rspamd_lua_parse_table_arguments
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 14 Apr 2020 14:25:34 +0000 (15:25 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 14 Apr 2020 14:25:34 +0000 (15:25 +0100)
src/lua/lua_common.c
src/lua/lua_common.h

index 8a562f7b3157db58acaa725e07b76bb902c65f2e..2be91140acc89790a87ffef57e6c135dd7472ece 100644 (file)
@@ -1449,6 +1449,38 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos,
                                }
                                break;
 
+                       case 'i':
+                               if (t == LUA_TNUMBER) {
+                                       *(va_arg (ap, gint32 *)) = lua_tointeger (L, idx);
+                               }
+                               else if (t == LUA_TNIL || t == LUA_TNONE) {
+                                       failed = TRUE;
+                                       if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) {
+                                               *(va_arg (ap, gint32 *)) = 0;
+                                       }
+                                       else {
+                                               (void)va_arg (ap, gint32 *);
+                                       }
+                               }
+                               else {
+                                       g_set_error (err,
+                                                       lua_error_quark (),
+                                                       1,
+                                                       "bad type for key:"
+                                                       " %.*s: '%s', '%s' is expected",
+                                                       (gint) keylen,
+                                                       key,
+                                                       lua_typename (L, lua_type (L, idx)),
+                                                       "int64");
+                                       va_end (ap);
+
+                                       return FALSE;
+                               }
+                               if (is_table) {
+                                       lua_pop (L, 1);
+                               }
+                               break;
+
                        case 'F':
                                if (t == LUA_TFUNCTION) {
                                        if (!is_table) {
index 8252da0049842bba13d702a8e1dae11c50bdbf33..5edec663b91c6fc6971eaa848347cfe6cd546b54 100644 (file)
@@ -411,18 +411,20 @@ enum rspamd_lua_parse_arguments_flags {
  * [*]key=S|I|N|B|V|U{a-z};[key=...]
  * - S - const char *
  * - I - gint64_t
+ * - i - int32_t
  * - N - double
- * - B - boolean
+ * - B - gboolean
  * - V - size_t + const char *
  * - U{classname} - userdata of the following class (stored in gpointer)
  * - F - function
  * - O - ucl_object_t *
+ * - D - same as N but argument is set to NAN not to 0.0
  *
  * If any of keys is prefixed with `*` then it is treated as required argument
  * @param L lua state
  * @param pos at which pos start extraction
  * @param err error pointer
- * @param how extraction type
+ * @param how extraction type (IGNORE_MISSING means that default values will not be set)
  * @param extraction_pattern static pattern
  * @return TRUE if a table has been parsed
  */