From dedf8c57ddf2ec633e0d69205e98eb3b8d27a80b Mon Sep 17 00:00:00 2001 From: Marek Vavrusa <marek@vavrusa.com> Date: Tue, 5 Jul 2016 00:30:02 -0700 Subject: [PATCH] daemon/engine: fixed unpacking of POD JSON vars --- daemon/engine.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/daemon/engine.c b/daemon/engine.c index 3ab9bbaa5..f0bcfe69a 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -250,10 +250,17 @@ static int l_trustanchor(lua_State *L) lua_pushboolean(L, true); return 1; } - /** Unpack JSON object to table */ static void l_unpack_json(lua_State *L, JsonNode *table) { + /* Unpack POD */ + switch(table->tag) { + case JSON_STRING: lua_pushstring(L, table->string_); return; + case JSON_NUMBER: lua_pushnumber(L, table->number_); return; + case JSON_BOOL: lua_pushboolean(L, table->bool_); return; + default: break; + } + /* Unpack object or array into table */ lua_newtable(L); JsonNode *node = NULL; json_foreach(node, table) { @@ -369,7 +376,7 @@ static int l_trampoline(lua_State *L) return 0; } JsonNode *root_node = json_decode(ret); - if (root_node && (root_node->tag == JSON_OBJECT || root_node->tag == JSON_ARRAY)) { + if (root_node) { l_unpack_json(L, root_node); } else { lua_pushstring(L, ret); -- GitLab