From 9ec9f02eb9fa2faf60873547a14b758240289398 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 13 Aug 2024 15:07:06 +0100 Subject: [PATCH] [Fix] Make tostring in UCL a bit less brain-damaged --- contrib/libucl/lua_ucl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/contrib/libucl/lua_ucl.c b/contrib/libucl/lua_ucl.c index 3e3a06605..79c658615 100644 --- a/contrib/libucl/lua_ucl.c +++ b/contrib/libucl/lua_ucl.c @@ -1146,8 +1146,9 @@ lua_ucl_object_tostring(lua_State *L) enum ucl_emitter format = UCL_EMIT_JSON_COMPACT; obj = lua_ucl_object_get(L, 1); + int type = ucl_object_type(obj); - if (obj) { + if (type == UCL_ARRAY || type == UCL_OBJECT) { if (lua_gettop(L) > 1) { if (lua_type(L, 2) == LUA_TSTRING) { const char *strtype = lua_tostring(L, 2); @@ -1158,9 +1159,12 @@ lua_ucl_object_tostring(lua_State *L) return lua_ucl_to_string(L, obj, format); } - else { + else if (type == UCL_NULL) { lua_pushnil(L); } + else { + ucl_object_lua_push_scalar(L, obj, 0); + } return 1; } -- 2.39.5