From f12b964f590c4ca05d0c8f9b06d792b5c6a8543e Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Wed, 8 Feb 2023 00:03:01 +0100 Subject: [PATCH] Use Plugin destructor to call lua_close in most cases reloading still needs manual closing --- src/controllers/plugins/Plugin.cpp | 12 ++++++++++++ src/controllers/plugins/Plugin.hpp | 2 ++ src/controllers/plugins/PluginController.cpp | 6 +----- 3 files changed, 15 insertions(+), 5 deletions(-) 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))