]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Support NANable numbers
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Nov 2016 19:52:55 +0000 (19:52 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Nov 2016 19:52:55 +0000 (19:52 +0000)
src/lua/lua_common.c

index 0e577326a958a4d68854073a8b6b5bbe5ddaf885..5a1cc7101fc59fa6d7705be051cec88449f0ddb2 100644 (file)
@@ -17,6 +17,7 @@
 #include "lua/global_functions.lua.h"
 #include "lptree.h"
 #include "utlist.h"
+#include <math.h>
 
 /* Lua module init function */
 #define MODULE_INIT_FUNC "module_init"
@@ -712,6 +713,34 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos,
                                }
                                break;
 
+                       case 'D':
+                               if (t == LUA_TNUMBER) {
+                                       *(va_arg (ap, gdouble *)) = lua_tonumber (L, idx);
+                               }
+                               else if (t == LUA_TNIL || t == LUA_TNONE) {
+                                       failed = TRUE;
+                                       *(va_arg (ap,  gdouble *)) = NAN;
+                               }
+                               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)),
+                                                       "double");
+                                       va_end (ap);
+
+                                       return FALSE;
+                               }
+
+                               if (is_table) {
+                                       lua_pop (L, 1);
+                               }
+                               break;
+
                        case 'V':
                                valuelen = va_arg (ap, gsize *);