Add callEveryWithArgs

This commit is contained in:
Mm2PL 2023-01-29 22:58:31 +01:00
parent c5688dd033
commit f5f0a3301f
No known key found for this signature in database
GPG key ID: 94AC9B80EFA15ED9
2 changed files with 20 additions and 0 deletions

View file

@ -4,6 +4,10 @@
#include "common/QLogging.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/WindowManager.hpp"
#include "widgets/Notebook.hpp"
#include "widgets/splits/Split.hpp"
#include "widgets/Window.hpp"
#include <memory>
#include <utility>
@ -70,6 +74,18 @@ void PluginController::callEvery(const QString &functionName)
}
}
void PluginController::callEveryWithArgs(
const QString &functionName, int count,
std::function<void(const std::unique_ptr<Plugin> &pl, lua_State *L)> argCb)
{
for (const auto &[name, plugin] : this->plugins)
{
lua_getglobal(plugin->state_, functionName.toStdString().c_str());
argCb(plugin, plugin->state_);
lua_pcall(plugin->state_, count, 0, 0);
}
}
constexpr int C_FALSE = 0;
constexpr int C_TRUE = 1;

View file

@ -50,6 +50,10 @@ public:
void initialize(Settings &settings, Paths &paths) override;
void save() override{};
void callEvery(const QString &functionName);
void callEveryWithArgs(
const QString &functionName, int count,
std::function<void(const std::unique_ptr<Plugin> &pl, lua_State *L)>
argCb);
private:
void load(QFileInfo index, QDir pluginDir);