Skip to content

Commit

Permalink
Updated to use dmScript::LuaToJson()
Browse files Browse the repository at this point in the history
  • Loading branch information
AGulev committed Nov 2, 2022
1 parent 85c5f61 commit baa7483
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
6 changes: 3 additions & 3 deletions jstodef/lib/web/lib_jstodef.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
19 changes: 1 addition & 18 deletions jstodef/src/jstodef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit baa7483

Please sign in to comment.