From c9d499a3bbd57df13c073798f4cae03272509625 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Tue, 15 Apr 2025 04:38:41 +0500 Subject: feat: array_contains function --- bot/src/commands/lua.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'bot') diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index 22233bb..cab5cb4 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -489,12 +489,39 @@ namespace bot::command::lua { }); } + void add_array_library(std::shared_ptr state) { + state->set_function("array_contains", [](const sol::table &haystack, + const long long &needle) { + bool o = false; + for (auto &[_, v] : haystack) { + if (v.is()) { + o = v.as() == needle; + if (o) break; + } + } + return o; + }); + + state->set_function("array_contains", [](const sol::table &haystack, + const std::string &needle) { + bool o = false; + for (auto &[_, v] : haystack) { + if (v.is()) { + o = v.as() == needle; + if (o) break; + } + } + return o; + }); + } + void add_base_libraries(std::shared_ptr state) { add_bot_library(state); add_time_library(state); add_json_library(state); add_net_library(state); add_string_library(state); + add_array_library(state); } void add_chat_libraries(std::shared_ptr state, -- cgit v1.2.3