From a8cfae1690c3fb6033065738788815f264749b5e Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 23 Jul 2025 01:08:41 +0500 Subject: feat: str_format function --- bot/src/commands/lua.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'bot/src/commands') diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index b7173ab..f0d3dab 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -1,5 +1,7 @@ #include "commands/lua.hpp" +#include +#include #include #include #include @@ -410,6 +412,23 @@ namespace bot::command::lua { } void add_string_library(std::shared_ptr state) { + state->set_function("str_format", + [](const std::string &str, const sol::table ¶ms) { + std::vector p; + std::string s = str; + long pos = std::string::npos; + for (const auto &x : params) { + if (x.second.is()) { + pos = s.find("{}"); + if (pos == std::string::npos) { + break; + } + s.replace(pos, 2, x.second.as()); + } + } + return s; + }); + state->set_function( "str_split", [state](const std::string &text, const char &delimiter) { sol::table o = state->create_table(); -- cgit v1.2.3