Use Plugin destructor to call lua_close in most cases

reloading still needs manual closing
This commit is contained in:
Mm2PL 2023-02-08 00:03:01 +01:00
parent 26a5a24eea
commit f12b964f59
No known key found for this signature in database
GPG key ID: 94AC9B80EFA15ED9
3 changed files with 15 additions and 5 deletions

View file

@ -1,6 +1,9 @@
#include "Plugin.hpp" #include "Plugin.hpp"
#ifdef CHATTERINO_HAVE_PLUGINS #ifdef CHATTERINO_HAVE_PLUGINS
# include "lua.h"
namespace chatterino { namespace chatterino {
bool Plugin::registerCommand(const QString &name, const QString &functionName) bool Plugin::registerCommand(const QString &name, const QString &functionName)
{ {
@ -27,5 +30,14 @@ std::set<QString> Plugin::listRegisteredCommands()
} }
return out; return out;
} }
Plugin::~Plugin()
{
if (this->state_ != nullptr)
{
lua_close(this->state_);
}
}
} // namespace chatterino } // namespace chatterino
#endif #endif

View file

@ -125,6 +125,8 @@ public:
{ {
} }
~Plugin();
bool registerCommand(const QString &name, const QString &functionName); bool registerCommand(const QString &name, const QString &functionName);
std::set<QString> listRegisteredCommands(); std::set<QString> listRegisteredCommands();

View file

@ -35,11 +35,6 @@ void PluginController::initialize(Settings &settings, Paths &paths)
else else
{ {
// uninitialize plugins // 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(); this->plugins_.clear();
} }
}); });
@ -54,6 +49,7 @@ void PluginController::actuallyInitialize()
<< "Loading plugins disabled via Setting, skipping"; << "Loading plugins disabled via Setting, skipping";
return; return;
} }
this->plugins_.clear();
auto dir = QDir(getPaths()->pluginsDirectory); auto dir = QDir(getPaths()->pluginsDirectory);
qCDebug(chatterinoLua) << "Loading plugins in" << dir.path(); qCDebug(chatterinoLua) << "Loading plugins in" << dir.path();
for (const auto &info : dir.entryInfoList(QDir::NoDotAndDotDot)) for (const auto &info : dir.entryInfoList(QDir::NoDotAndDotDot))