From 9b15126f3cc2a3c65d57e1d5c044105a5e75d154 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 25 Jun 2015 14:20:52 +0100 Subject: [PATCH] Fix get_all_opts for a case of non-iterable options. --- src/lua/lua_config.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 3e7ba80e2..54ac7a6d3 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -411,6 +411,7 @@ lua_config_get_all_opt (lua_State * L) const gchar *mname; const ucl_object_t *obj, *cur, *cur_elt; ucl_object_iter_t it = NULL; + gint i; if (cfg) { mname = luaL_checkstring (L, 2); @@ -418,7 +419,8 @@ lua_config_get_all_opt (lua_State * L) if (mname) { obj = ucl_obj_get_key (cfg->rcl_obj, mname); /* Flatten object */ - if (obj != NULL && ucl_object_type (obj) == UCL_OBJECT) { + if (obj != NULL && (ucl_object_type (obj) == UCL_OBJECT || + ucl_object_type (obj) == UCL_ARRAY)) { lua_newtable (L); it = ucl_object_iterate_new (obj); @@ -435,6 +437,18 @@ lua_config_get_all_opt (lua_State * L) ucl_object_iterate_free (it); + return 1; + } + else if (obj != NULL) { + lua_newtable (L); + i = 1; + + LL_FOREACH (obj, cur) { + lua_pushnumber (L, i++); + ucl_object_push_lua (L, cur, true); + lua_settable (L, -3); + } + return 1; } } -- 2.39.5