summaryrefslogtreecommitdiffstats
path: root/contrib/libucl/lua_ucl.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-08 13:01:08 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-08 13:01:08 +0100
commit9b74e57ad3fb694741fdcf5e27a046fbe99a40f7 (patch)
tree3080fb43edac872ca98c4fe3c5953e59d02ceef9 /contrib/libucl/lua_ucl.c
parent3d8f5c5e7f4ee08aa033805313fe9b5585a2d4fa (diff)
downloadrspamd-9b74e57ad3fb694741fdcf5e27a046fbe99a40f7.tar.gz
rspamd-9b74e57ad3fb694741fdcf5e27a046fbe99a40f7.zip
[Feature] Libucl: Allow to sort keys in ucl objects
Diffstat (limited to 'contrib/libucl/lua_ucl.c')
-rw-r--r--contrib/libucl/lua_ucl.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/contrib/libucl/lua_ucl.c b/contrib/libucl/lua_ucl.c
index b97387d9e..049b1d08c 100644
--- a/contrib/libucl/lua_ucl.c
+++ b/contrib/libucl/lua_ucl.c
@@ -1368,6 +1368,7 @@ lua_ucl_to_format (lua_State *L)
{
ucl_object_t *obj;
int format = UCL_EMIT_JSON;
+ bool sort = false;
if (lua_gettop (L) > 1) {
if (lua_type (L, 2) == LUA_TNUMBER) {
@@ -1397,10 +1398,22 @@ lua_ucl_to_format (lua_State *L)
format = UCL_EMIT_MSGPACK;
}
}
+
+ if (lua_isboolean (L, 3)) {
+ sort = lua_toboolean (L, 3);
+ }
}
obj = ucl_object_lua_import (L, 1);
+
if (obj != NULL) {
+
+ if (sort) {
+ if (ucl_object_type (obj) == UCL_OBJECT) {
+ ucl_object_sort_keys (obj, UCL_SORT_KEYS_RECURSIVE);
+ }
+ }
+
lua_ucl_to_string (L, obj, format);
ucl_object_unref (obj);
}