Skip to content

Commit 8a685a2

Browse files
authored
Merge pull request #49 from defold/lua-to-json
Updated to dmScript::LuaToJson()
2 parents 7149a08 + 41148f0 commit 8a685a2

File tree

1 file changed

+3
-32
lines changed

1 file changed

+3
-32
lines changed

facebook/src/facebook_util.cpp

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "facebook_private.h"
22
#include "facebook_util.h"
33
#include <dmsdk/dlib/log.h>
4-
#include <dmsdk/dlib/json.h>
54
#include <dmsdk/dlib/dstrings.h>
65
#include <dmsdk/script/script.h>
76

@@ -567,18 +566,8 @@ size_t dmFacebook::CountStringArrayLength(lua_State* L, int table_index, size_t&
567566

568567
int dmFacebook::PushLuaTableFromJson(lua_State* L, const char* json)
569568
{
570-
char err_str[512] = {0};
571-
int err = 0;
572-
dmJson::Document doc;
573-
dmJson::Result r = dmJson::Parse(json, &doc);
574-
if (r == dmJson::RESULT_OK && doc.m_NodeCount > 0) {
575-
dmScript::JsonToLua(L, &doc, 0, err_str, sizeof(err_str));
576-
} else {
577-
dmLogError("Failed to parse JSON (%d): %s", r, err_str);
578-
err = 1;
579-
}
580-
dmJson::Free(&doc);
581-
return err;
569+
dmScript::JsonToLua(L, json, strlen(json)); // throws lua error if it fails
570+
return 0;
582571
}
583572

584573
void dmFacebook::RunStatusCallback(dmScript::LuaCallbackInfo* callback, const char* error, int status)
@@ -621,25 +610,7 @@ void dmFacebook::RunJsonResultCallback(dmScript::LuaCallbackInfo* callback, cons
621610
}
622611
else
623612
{
624-
bool is_fail = false;
625-
dmJson::Document doc;
626-
dmJson::Result r = dmJson::Parse(json, &doc);
627-
if (r == dmJson::RESULT_OK && doc.m_NodeCount > 0) {
628-
char error_str_out[128];
629-
if (dmScript::JsonToLua(L, &doc, 0, error_str_out, sizeof(error_str_out)) < 0) {
630-
dmLogError("Failed converting object JSON to Lua: %s", error_str_out);
631-
is_fail = true;
632-
}
633-
} else {
634-
dmLogError("Failed to parse JSON object(%d): (%s)", r, json);
635-
is_fail = true;
636-
}
637-
dmJson::Free(&doc);
638-
if (is_fail) {
639-
lua_pop(L, 2);
640-
dmScript::TeardownCallback(callback);
641-
return;
642-
}
613+
dmScript::JsonToLua(L, json, strlen(json)); // throws lua error if it fails
643614
}
644615

645616
dmFacebook::PushError(L, error);

0 commit comments

Comments
 (0)