From f649ead41180d3fc2c24480c843b0cf4bb636f97 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 10 Apr 2025 21:56:17 +0500 Subject: feat: get json value by string path (new lua function) --- bot/src/commands/lua.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'bot') diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index b8d0dee..589fd27 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -180,6 +180,18 @@ namespace bot::command::lua { state->set_function("json_stringify", [](const sol::object &o) { return lua_to_json(o).dump(); }); + + state->set_function("json_get_value", [state](const sol::object &body, + const std::string &path) { + std::vector parts = utils::string::split_text(path, '.'); + nlohmann::json o = lua_to_json(body); + + for (const std::string &path : parts) { + o = o[path]; + } + + return parse_json_object(state, o); + }); } void add_net_library(std::shared_ptr state) { -- cgit v1.2.3