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:
@@ -18,8 +18,6 @@ add_qtc_plugin(Lua
|
|||||||
luaengine.cpp
|
luaengine.cpp
|
||||||
luaengine.h
|
luaengine.h
|
||||||
luaplugin.cpp
|
luaplugin.cpp
|
||||||
luapluginloader.cpp
|
|
||||||
luapluginloader.h
|
|
||||||
luapluginspec.cpp
|
luapluginspec.cpp
|
||||||
luapluginspec.h
|
luapluginspec.h
|
||||||
luaqttypes.cpp
|
luaqttypes.cpp
|
||||||
|
@@ -15,8 +15,6 @@ QtcPlugin {
|
|||||||
"luaengine.cpp",
|
"luaengine.cpp",
|
||||||
"luaengine.h",
|
"luaengine.h",
|
||||||
"luaplugin.cpp",
|
"luaplugin.cpp",
|
||||||
"luapluginloader.cpp",
|
|
||||||
"luapluginloader.h",
|
|
||||||
"luapluginspec.cpp",
|
"luapluginspec.cpp",
|
||||||
"luapluginspec.h",
|
"luapluginspec.h",
|
||||||
"luaqttypes.cpp",
|
"luaqttypes.cpp",
|
||||||
|
@@ -2,19 +2,20 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "luaengine.h"
|
#include "luaengine.h"
|
||||||
#include "luapluginloader.h"
|
#include "luapluginspec.h"
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
#include <QAction>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMenu>
|
|
||||||
|
using namespace Core;
|
||||||
|
using namespace Utils;
|
||||||
|
using namespace ExtensionSystem;
|
||||||
|
|
||||||
namespace Lua::Internal {
|
namespace Lua::Internal {
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ void addQtModule();
|
|||||||
void addCoreModule();
|
void addCoreModule();
|
||||||
void addHookModule();
|
void addHookModule();
|
||||||
|
|
||||||
class LuaPlugin : public ExtensionSystem::IPlugin
|
class LuaPlugin : public IPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Lua.json")
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Lua.json")
|
||||||
@@ -39,13 +40,13 @@ private:
|
|||||||
std::unique_ptr<LuaEngine> m_luaEngine;
|
std::unique_ptr<LuaEngine> m_luaEngine;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LuaPlugin()
|
LuaPlugin() {}
|
||||||
: m_luaEngine(new LuaEngine())
|
|
||||||
{}
|
|
||||||
~LuaPlugin() override = default;
|
~LuaPlugin() override = default;
|
||||||
|
|
||||||
void initialize() final
|
void initialize() final
|
||||||
{
|
{
|
||||||
|
m_luaEngine.reset(new LuaEngine());
|
||||||
|
|
||||||
addAsyncModule();
|
addAsyncModule();
|
||||||
addFetchModule();
|
addFetchModule();
|
||||||
addActionModule();
|
addActionModule();
|
||||||
@@ -61,12 +62,39 @@ public:
|
|||||||
|
|
||||||
bool delayedInitialize() final
|
bool delayedInitialize() final
|
||||||
{
|
{
|
||||||
LuaPluginLoader::instance().scan(
|
scanForPlugins(transform(PluginManager::pluginPaths(), [](const QString &path) -> FilePath {
|
||||||
Utils::transform(ExtensionSystem::PluginManager::pluginPaths(),
|
return FilePath::fromUserInput(path) / "lua-plugins";
|
||||||
[](const QString &path) -> QString { return path + "/lua-plugins/"; }));
|
}));
|
||||||
|
|
||||||
return true;
|
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
|
} // namespace Lua::Internal
|
||||||
|
@@ -1,64 +0,0 @@
|
|||||||
// Copyright (C) 2024 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#include "luapluginloader.h"
|
|
||||||
|
|
||||||
#include "luaengine.h"
|
|
||||||
#include "luapluginspec.h"
|
|
||||||
|
|
||||||
#include <coreplugin/messagemanager.h>
|
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
|
||||||
#include <extensionsystem/pluginspec.h>
|
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
|
||||||
#include <utils/filepath.h>
|
|
||||||
|
|
||||||
namespace Lua {
|
|
||||||
|
|
||||||
class LuaPluginLoaderPrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
};
|
|
||||||
|
|
||||||
LuaPluginLoader::LuaPluginLoader()
|
|
||||||
: d(std::make_unique<LuaPluginLoaderPrivate>())
|
|
||||||
{}
|
|
||||||
LuaPluginLoader::~LuaPluginLoader() = default;
|
|
||||||
|
|
||||||
LuaPluginLoader &LuaPluginLoader::instance()
|
|
||||||
{
|
|
||||||
static LuaPluginLoader luaPluginLoader;
|
|
||||||
return luaPluginLoader;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LuaPluginLoader::scan(const QStringList &paths)
|
|
||||||
{
|
|
||||||
QVector<ExtensionSystem::PluginSpec *> plugins;
|
|
||||||
for (const auto &path : paths) {
|
|
||||||
const auto folders = Utils::FilePath::fromUserInput(path).dirEntries(
|
|
||||||
Utils::FileFilter({}, QDir::Dirs | QDir::NoDotAndDotDot));
|
|
||||||
|
|
||||||
for (const auto &folder : folders) {
|
|
||||||
const auto script = folder / (folder.baseName() + ".lua");
|
|
||||||
const Utils::expected_str<LuaPluginSpec *> result = LuaEngine::instance().loadPlugin(
|
|
||||||
script);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
qWarning() << "Failed to load plugin" << script << ":" << result.error();
|
|
||||||
Core::MessageManager::writeFlashing(tr("Failed to load plugin %1: %2")
|
|
||||||
.arg(script.toUserOutput())
|
|
||||||
.arg(result.error()));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins.push_back(*result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ExtensionSystem::PluginManager::addPlugins(plugins);
|
|
||||||
ExtensionSystem::PluginManager::loadPluginsAtRuntime(
|
|
||||||
QSet<ExtensionSystem::PluginSpec *>(plugins.begin(), plugins.end()));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Lua
|
|
@@ -1,30 +0,0 @@
|
|||||||
// Copyright (C) 2024 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace Lua {
|
|
||||||
class LuaPluginLoaderPrivate;
|
|
||||||
class LuaPluginLoader : public QObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LuaPluginLoader();
|
|
||||||
~LuaPluginLoader();
|
|
||||||
|
|
||||||
static LuaPluginLoader &instance();
|
|
||||||
|
|
||||||
void scan(const QStringList &paths);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void pluginLoaded(const QString &name);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<LuaPluginLoaderPrivate> d;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Lua
|
|
Reference in New Issue
Block a user