diff options
| author | ilotterytea <iltsu@alright.party> | 2025-04-10 21:56:17 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-04-10 21:56:17 +0500 |
| commit | f649ead41180d3fc2c24480c843b0cf4bb636f97 (patch) | |
| tree | eb74c3a8ce10254aba388a2856abbc6ec4f3f43b /bot/src/commands/lua.cpp | |
| parent | 0487cb46d45ebb23161f9ef8f3135c04a5010b59 (diff) | |
feat: get json value by string path (new lua function)
Diffstat (limited to 'bot/src/commands/lua.cpp')
| -rw-r--r-- | bot/src/commands/lua.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
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<std::string> 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<sol::state> state) { |
