diff --git a/src/controllers/plugins/Plugin.cpp b/src/controllers/plugins/Plugin.cpp index 5d3400a79..5769b106d 100644 --- a/src/controllers/plugins/Plugin.cpp +++ b/src/controllers/plugins/Plugin.cpp @@ -1,6 +1,9 @@ #include "Plugin.hpp" + #ifdef CHATTERINO_HAVE_PLUGINS +# include "lua.h" + namespace chatterino { bool Plugin::registerCommand(const QString &name, const QString &functionName) { @@ -27,5 +30,14 @@ std::set Plugin::listRegisteredCommands() } return out; } + +Plugin::~Plugin() +{ + if (this->state_ != nullptr) + { + lua_close(this->state_); + } +} + } // namespace chatterino #endif diff --git a/src/controllers/plugins/Plugin.hpp b/src/controllers/plugins/Plugin.hpp index 71095a377..7edc3f96b 100644 --- a/src/controllers/plugins/Plugin.hpp +++ b/src/controllers/plugins/Plugin.hpp @@ -125,6 +125,8 @@ public: { } + ~Plugin(); + bool registerCommand(const QString &name, const QString &functionName); std::set listRegisteredCommands(); diff --git a/src/controllers/plugins/PluginController.cpp b/src/controllers/plugins/PluginController.cpp index 6cd30810e..2d8238f0e 100644 --- a/src/controllers/plugins/PluginController.cpp +++ b/src/controllers/plugins/PluginController.cpp @@ -35,11 +35,6 @@ void PluginController::initialize(Settings &settings, Paths &paths) else { // uninitialize plugins - for (const auto &[codename, plugin] : this->plugins_) - { - this->reload(codename); - } - // can safely delete them now, after lua freed its stuff this->plugins_.clear(); } }); @@ -54,6 +49,7 @@ void PluginController::actuallyInitialize() << "Loading plugins disabled via Setting, skipping"; return; } + this->plugins_.clear(); auto dir = QDir(getPaths()->pluginsDirectory); qCDebug(chatterinoLua) << "Loading plugins in" << dir.path(); for (const auto &info : dir.entryInfoList(QDir::NoDotAndDotDot))