diff options
| author | ilotterytea <iltsu@alright.party> | 2025-07-23 01:08:41 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-07-23 01:08:41 +0500 |
| commit | a8cfae1690c3fb6033065738788815f264749b5e (patch) | |
| tree | 2917a5f0aea124e13829c5d51237ca26eb810138 | |
| parent | 6da71eb3e118dbd6f55830922f6ef98cd6960147 (diff) | |
feat: str_format function
| -rw-r--r-- | bot/src/commands/lua.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
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 <fmt/core.h> +#include <fmt/std.h> #include <sys/resource.h> #include <sys/types.h> #include <unistd.h> @@ -410,6 +412,23 @@ namespace bot::command::lua { } void add_string_library(std::shared_ptr<sol::state> state) { + state->set_function("str_format", + [](const std::string &str, const sol::table ¶ms) { + std::vector<std::string> p; + std::string s = str; + long pos = std::string::npos; + for (const auto &x : params) { + if (x.second.is<std::string>()) { + pos = s.find("{}"); + if (pos == std::string::npos) { + break; + } + s.replace(pos, 2, x.second.as<std::string>()); + } + } + return s; + }); + state->set_function( "str_split", [state](const std::string &text, const char &delimiter) { sol::table o = state->create_table(); |
