diff options
Diffstat (limited to 'bot/src/commands/lua.cpp')
| -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(); |
