Add nlohmann json

This commit is contained in:
momo5502
2025-04-23 15:30:36 +02:00
parent 1beb95c2b2
commit 6a302aff69
5 changed files with 33 additions and 5 deletions

View File

@@ -16,6 +16,7 @@ endif()
target_link_libraries(debugger PRIVATE
windows-emulator
nlohmann_json
)
set_property(GLOBAL PROPERTY VS_STARTUP_PROJECT debugger)

View File

@@ -2,6 +2,7 @@
#include <windows_emulator.hpp>
#include <cstdio>
#include <nlohmann/json.hpp>
#ifdef OS_EMSCRIPTEN
#include <emscripten.h>
@@ -73,18 +74,35 @@ namespace
#endif
}
void handle_messages()
void send_object(const nlohmann::json& json)
{
const std::string res = json.dump();
send_message(res);
}
nlohmann::json receive_object()
{
auto message = receive_message();
if (message.empty())
{
return {};
}
return nlohmann::json::parse(message);
}
void handle_messages(windows_emulator& win_emu)
{
while (true)
{
suspend_execution(0ms);
const auto message = receive_message();
if (message.empty())
const auto message = receive_object();
if (message.is_null())
{
break;
}
puts(message.c_str());
puts(message.dump().c_str());
}
}
@@ -144,7 +162,7 @@ namespace
windows_emulator win_emu{app_settings, settings};
win_emu.callbacks.on_thread_switch = [&] {
handle_messages(); //
handle_messages(win_emu); //
};
return run_emulation(win_emu);