From dbc0a928b9537938b0651daf7e5ebad2a45fcb41 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sun, 20 Jun 2021 00:36:07 +0200 Subject: [PATCH] Add jsonPrint function --- src/component/io.cpp | 15 +++++++++++++++ src/component/json.cpp | 6 ++++++ src/component/json.hpp | 6 ++++++ 3 files changed, 27 insertions(+) create mode 100644 src/component/json.hpp diff --git a/src/component/io.cpp b/src/component/io.cpp index 4a01a2d..cbce74b 100644 --- a/src/component/io.cpp +++ b/src/component/io.cpp @@ -9,6 +9,7 @@ #include "game/scripting/array.hpp" #include "gsc.hpp" +#include "json.hpp" namespace io { @@ -20,6 +21,20 @@ namespace io const auto path = game::Dvar_FindVar("fs_basegame")->current.string; std::filesystem::current_path(path); + gsc::function::add("jsonprint", [](const gsc::function_args& args) -> scripting::script_value + { + std::string buffer; + + for (const auto arg : args.get_raw()) + { + buffer.append(json::gsc_to_string(arg)); + buffer.append("\t"); + } + + printf("%s\n", buffer.data()); + return {}; + }); + gsc::function::add("fremove", [](const gsc::function_args& args) { const auto path = args[0].as(); diff --git a/src/component/json.cpp b/src/component/json.cpp index ce91499..0377177 100644 --- a/src/component/json.cpp +++ b/src/component/json.cpp @@ -9,6 +9,7 @@ #include "game/scripting/array.hpp" #include "gsc.hpp" +#include "json.hpp" #include @@ -136,6 +137,11 @@ namespace json } } + std::string gsc_to_string(const scripting::script_value& value) + { + return gsc_to_json(value).dump(); + } + class component final : public component_interface { public: diff --git a/src/component/json.hpp b/src/component/json.hpp new file mode 100644 index 0000000..747717c --- /dev/null +++ b/src/component/json.hpp @@ -0,0 +1,6 @@ +#pragma once + +namespace json +{ + std::string gsc_to_string(const scripting::script_value& _value); +} \ No newline at end of file