From 75a8e1fa3713588d723e05b92686346333800f78 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 7 Apr 2015 18:19:20 +0100 Subject: [PATCH] Fix pushing array to lua from UCL. --- contrib/libucl/lua_ucl.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/contrib/libucl/lua_ucl.c b/contrib/libucl/lua_ucl.c index 682b0b559..1f79b0e16 100644 --- a/contrib/libucl/lua_ucl.c +++ b/contrib/libucl/lua_ucl.c @@ -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); } -- 2.39.5