forked from qt-creator/qt-creator
Lua: Cleanup
Moves LuaEngine creation into initialize() Removes uneccessary PluginLoader class Change-Id: I9eddbe4d0cba7ba3c7c1ce825ec18845de7d4654 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -2,19 +2,20 @@
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "luaengine.h"
|
||||
#include "luapluginloader.h"
|
||||
#include "luapluginspec.h"
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/messagemanager.h>
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Utils;
|
||||
using namespace ExtensionSystem;
|
||||
|
||||
namespace Lua::Internal {
|
||||
|
||||
@@ -30,7 +31,7 @@ void addQtModule();
|
||||
void addCoreModule();
|
||||
void addHookModule();
|
||||
|
||||
class LuaPlugin : public ExtensionSystem::IPlugin
|
||||
class LuaPlugin : public IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Lua.json")
|
||||
@@ -39,13 +40,13 @@ private:
|
||||
std::unique_ptr<LuaEngine> m_luaEngine;
|
||||
|
||||
public:
|
||||
LuaPlugin()
|
||||
: m_luaEngine(new LuaEngine())
|
||||
{}
|
||||
LuaPlugin() {}
|
||||
~LuaPlugin() override = default;
|
||||
|
||||
void initialize() final
|
||||
{
|
||||
m_luaEngine.reset(new LuaEngine());
|
||||
|
||||
addAsyncModule();
|
||||
addFetchModule();
|
||||
addActionModule();
|
||||
@@ -61,12 +62,39 @@ public:
|
||||
|
||||
bool delayedInitialize() final
|
||||
{
|
||||
LuaPluginLoader::instance().scan(
|
||||
Utils::transform(ExtensionSystem::PluginManager::pluginPaths(),
|
||||
[](const QString &path) -> QString { return path + "/lua-plugins/"; }));
|
||||
scanForPlugins(transform(PluginManager::pluginPaths(), [](const QString &path) -> FilePath {
|
||||
return FilePath::fromUserInput(path) / "lua-plugins";
|
||||
}));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void scanForPlugins(const FilePaths &paths)
|
||||
{
|
||||
QSet<PluginSpec *> plugins;
|
||||
for (const FilePath &path : paths) {
|
||||
const FilePaths folders = path.dirEntries(
|
||||
FileFilter({}, QDir::Dirs | QDir::NoDotAndDotDot));
|
||||
|
||||
for (const FilePath &folder : folders) {
|
||||
const FilePath script = folder / (folder.baseName() + ".lua");
|
||||
const expected_str<LuaPluginSpec *> result = m_luaEngine->loadPlugin(script);
|
||||
|
||||
if (!result) {
|
||||
qWarning() << "Failed to load plugin" << script << ":" << result.error();
|
||||
MessageManager::writeFlashing(tr("Failed to load plugin %1: %2")
|
||||
.arg(script.toUserOutput())
|
||||
.arg(result.error()));
|
||||
continue;
|
||||
}
|
||||
|
||||
plugins.insert(*result);
|
||||
}
|
||||
}
|
||||
|
||||
PluginManager::addPlugins({plugins.begin(), plugins.end()});
|
||||
PluginManager::loadPluginsAtRuntime(plugins);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Lua::Internal
|
||||
|
Reference in New Issue
Block a user