]> source.dussan.org Git - rspamd.git/commitdiff
Fix pushing array to lua from UCL.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Apr 2015 17:19:20 +0000 (18:19 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Apr 2015 17:19:20 +0000 (18:19 +0100)
contrib/libucl/lua_ucl.c

index 682b0b559fd32e854721f85798eda74cd3d343ee..1f79b0e16ad3e5dfc29d5c3059374d09ddc0420c 100644 (file)
@@ -172,19 +172,33 @@ static int
 ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj)
 {
        const ucl_object_t *cur;
+       ucl_object_iter_t it;
        int i = 1, nelt = 0;
 
-       /* Optimize allocation by preallocation of table */
-       LL_FOREACH (obj, cur) {
-               nelt ++;
+       if (obj->type == UCL_ARRAY) {
+               nelt = obj->len;
+               it = ucl_object_iterate_new (obj);
+               lua_createtable (L, nelt, 0);
+
+               while ((cur = ucl_object_iterate_safe (it, true))) {
+                       ucl_object_push_lua (L, cur, false);
+                       lua_rawseti (L, -2, i);
+                       i ++;
+               }
        }
+       else {
+               /* Optimize allocation by preallocation of table */
+               LL_FOREACH (obj, cur) {
+                       nelt ++;
+               }
 
-       lua_createtable (L, nelt, 0);
+               lua_createtable (L, nelt, 0);
 
-       LL_FOREACH (obj, cur) {
-               ucl_object_push_lua (L, cur, false);
-               lua_rawseti (L, -2, i);
-               i ++;
+               LL_FOREACH (obj, cur) {
+                       ucl_object_push_lua (L, cur, false);
+                       lua_rawseti (L, -2, i);
+                       i ++;
+               }
        }
 
        return 1;
@@ -259,7 +273,7 @@ ucl_object_push_lua (lua_State *L, const ucl_object_t *obj, bool allow_array)
        case UCL_OBJECT:
                return ucl_object_lua_push_object (L, obj, allow_array);
        case UCL_ARRAY:
-               return ucl_object_lua_push_array (L, obj->value.av);
+               return ucl_object_lua_push_array (L, obj);
        default:
                return ucl_object_lua_push_scalar (L, obj, allow_array);
        }