mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 11:05:08 -05:00
matjson 2/?
Some checks are pending
Build Binaries / Build Windows (push) Waiting to run
Build Binaries / Build macOS (push) Waiting to run
Build Binaries / Build Android (64-bit) (push) Waiting to run
Build Binaries / Build Android (32-bit) (push) Waiting to run
Build Binaries / Publish (push) Blocked by required conditions
Some checks are pending
Build Binaries / Build Windows (push) Waiting to run
Build Binaries / Build macOS (push) Waiting to run
Build Binaries / Build Android (64-bit) (push) Waiting to run
Build Binaries / Build Android (32-bit) (push) Waiting to run
Build Binaries / Publish (push) Blocked by required conditions
This commit is contained in:
parent
f2ec5fa3f8
commit
108721dd3f
3 changed files with 13 additions and 16 deletions
|
@ -121,18 +121,16 @@ namespace geode {
|
|||
* @param name The argument name
|
||||
*/
|
||||
template <class T>
|
||||
Result<T> parseLaunchArgument(std::string_view const name) const {
|
||||
Result<T, std::string_view> parseLaunchArgument(std::string_view const name) const {
|
||||
auto str = this->getLaunchArgument(name);
|
||||
if (!str.has_value()) {
|
||||
return std::nullopt;
|
||||
return Err("Launch argument '{}' not found", name);
|
||||
}
|
||||
std::string parseError;
|
||||
auto jsonOpt = matjson::parse(str.value(), parseError);
|
||||
if (!jsonOpt.has_value()) {
|
||||
log::debug("Parsing launch argument '{}' failed: {}", name, parseError);
|
||||
return std::nullopt;
|
||||
auto jsonOpt = matjson::Value::parse(str.value());
|
||||
if (jsonOpt.isErr()) {
|
||||
return Err("Parsing launch argument '{}' failed: {}", name, jsonOpt.unwrapErr());
|
||||
}
|
||||
auto value = jsonOpt.value();
|
||||
auto value = jsonOpt.unwrap();
|
||||
return value.template as<T>();
|
||||
}
|
||||
|
||||
|
|
|
@ -265,7 +265,7 @@ namespace geode {
|
|||
}); res.isOk()) {
|
||||
return res.unwrap();
|
||||
}
|
||||
saved[key] = defaultValue;
|
||||
saved[key] = matjson::Value(defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,19 +33,18 @@ ipc::IPCFilter::IPCFilter(std::string const& modID, std::string const& messageID
|
|||
matjson::Value ipc::processRaw(void* rawHandle, std::string const& buffer) {
|
||||
matjson::Value reply;
|
||||
|
||||
std::string error;
|
||||
auto res = matjson::parse(buffer, error);
|
||||
auto res = matjson::Value::parse(buffer);
|
||||
if (error.size() > 0) {
|
||||
log::warn("Received IPC message that isn't valid JSON: {}", error);
|
||||
log::warn("Received IPC message that isn't valid JSON: {}", res.unwrapErr());
|
||||
return reply;
|
||||
}
|
||||
matjson::Value json = res.value();
|
||||
matjson::Value json = res.unwrap();
|
||||
|
||||
if (!json.contains("mod") || !json["mod"].is_string()) {
|
||||
if (!json.contains("mod") || !json["mod"].isString()) {
|
||||
log::warn("Received IPC message without 'mod' field");
|
||||
return reply;
|
||||
}
|
||||
if (!json.contains("message") || !json["message"].is_string()) {
|
||||
if (!json.contains("message") || !json["message"].isString()) {
|
||||
log::warn("Received IPC message without 'message' field");
|
||||
return reply;
|
||||
}
|
||||
|
@ -55,6 +54,6 @@ matjson::Value ipc::processRaw(void* rawHandle, std::string const& buffer) {
|
|||
}
|
||||
// log::debug("Posting IPC event");
|
||||
// ! warning: if the event system is ever made asynchronous this will break!
|
||||
IPCEvent(rawHandle, json["mod"].as_string(), json["message"].as_string(), data, reply).post();
|
||||
IPCEvent(rawHandle, json["mod"].asString().unwrap(), json["message"].asString().unwrap(), data, reply).post();
|
||||
return reply;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue