From baa7483aee459a4792a4ea74e3421a7b891dd1a4 Mon Sep 17 00:00:00 2001 From: AGulev Date: Wed, 2 Nov 2022 15:59:05 +0100 Subject: [PATCH] Updated to use dmScript::LuaToJson() --- jstodef/lib/web/lib_jstodef.js | 6 +++--- jstodef/src/jstodef.cpp | 19 +------------------ 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/jstodef/lib/web/lib_jstodef.js b/jstodef/lib/web/lib_jstodef.js index 3eabe00..78b3365 100644 --- a/jstodef/lib/web/lib_jstodef.js +++ b/jstodef/lib/web/lib_jstodef.js @@ -11,8 +11,8 @@ var LibJsToDef = { send: function(message_id, message){ if (JsToDef._callback_object) { if (!message_id) { - console.warn("You need to send message_id") - return + console.warn("You need to send message_id"); + return; } var msg_id = allocate(intArrayFromString(message_id), ALLOC_NORMAL); switch (typeof message) { @@ -36,7 +36,7 @@ var LibJsToDef = { Module._free(msg); } else { var msg = JSON.stringify(message); - var msg_arr = intArrayFromString(msg, true); + var msg_arr = intArrayFromString(msg, false); //zero-terminated msg = allocate(msg_arr, ALLOC_NORMAL); {{{ makeDynCall("viii", "JsToDef._callback_object")}}}(msg_id, msg, msg_arr.length); Module._free(msg); diff --git a/jstodef/src/jstodef.cpp b/jstodef/src/jstodef.cpp index 950c272..b507a92 100644 --- a/jstodef/src/jstodef.cpp +++ b/jstodef/src/jstodef.cpp @@ -79,24 +79,7 @@ static void JsToDef_SendObjectMessage(const char* message_id, const char* messag //[-1] - message_id //[-2] - self //[-3] - callback - dmJson::Document doc; - dmJson::Result r = dmJson::Parse(message, length, &doc); - if (r == dmJson::RESULT_OK && doc.m_NodeCount > 0) { - char error_str_out[128]; - if (dmScript::JsonToLua(L, &doc, 0, error_str_out, sizeof(error_str_out)) < 0) { - dmLogError("Failed converting object JSON to Lua; %s", error_str_out); - is_fail = true; - } - } else { - dmLogError("Failed to parse JS object(%d): (%s)", r, message); - is_fail = true; - } - dmJson::Free(&doc); - if (is_fail) { - lua_pop(L, 2); - assert(top == lua_gettop(L)); - return; - } + dmScript::JsonToLua(L, message, length); // throws lua error if it fails //[-1] - result lua table //[-2] - message_id //[-3] - self