2024-04-12 14:36:37 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
|
2024-05-02 14:33:21 +02:00
|
|
|
#include "luaengine.h"
|
2024-05-06 11:54:53 +02:00
|
|
|
#include "luapluginspec.h"
|
2024-04-12 14:36:37 +02:00
|
|
|
|
2024-05-06 11:54:53 +02:00
|
|
|
#include <coreplugin/messagemanager.h>
|
2024-04-12 14:36:37 +02:00
|
|
|
|
|
|
|
#include <extensionsystem/iplugin.h>
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
|
|
|
#include <QDebug>
|
2024-05-06 11:54:53 +02:00
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
using namespace Utils;
|
|
|
|
using namespace ExtensionSystem;
|
2024-04-12 14:36:37 +02:00
|
|
|
|
|
|
|
namespace Lua::Internal {
|
|
|
|
|
|
|
|
void addAsyncModule();
|
|
|
|
void addFetchModule();
|
|
|
|
void addActionModule();
|
|
|
|
void addUtilsModule();
|
|
|
|
void addMessageManagerModule();
|
|
|
|
void addProcessModule();
|
|
|
|
void addSettingsModule();
|
|
|
|
void addLayoutModule();
|
|
|
|
void addQtModule();
|
|
|
|
void addCoreModule();
|
|
|
|
void addHookModule();
|
|
|
|
|
2024-05-06 11:54:53 +02:00
|
|
|
class LuaPlugin : public IPlugin
|
2024-04-12 14:36:37 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Lua.json")
|
|
|
|
|
2024-05-02 14:33:21 +02:00
|
|
|
private:
|
|
|
|
std::unique_ptr<LuaEngine> m_luaEngine;
|
|
|
|
|
2024-04-12 14:36:37 +02:00
|
|
|
public:
|
2024-05-06 11:54:53 +02:00
|
|
|
LuaPlugin() {}
|
2024-04-12 14:36:37 +02:00
|
|
|
~LuaPlugin() override = default;
|
|
|
|
|
|
|
|
void initialize() final
|
|
|
|
{
|
2024-05-06 11:54:53 +02:00
|
|
|
m_luaEngine.reset(new LuaEngine());
|
|
|
|
|
2024-04-12 14:36:37 +02:00
|
|
|
addAsyncModule();
|
|
|
|
addFetchModule();
|
|
|
|
addActionModule();
|
|
|
|
addUtilsModule();
|
|
|
|
addMessageManagerModule();
|
|
|
|
addProcessModule();
|
|
|
|
addSettingsModule();
|
|
|
|
addLayoutModule();
|
|
|
|
addQtModule();
|
|
|
|
addCoreModule();
|
|
|
|
addHookModule();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool delayedInitialize() final
|
|
|
|
{
|
2024-05-06 11:54:53 +02:00
|
|
|
scanForPlugins(transform(PluginManager::pluginPaths(), [](const QString &path) -> FilePath {
|
|
|
|
return FilePath::fromUserInput(path) / "lua-plugins";
|
|
|
|
}));
|
2024-04-12 14:36:37 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2024-05-06 11:54:53 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2024-04-12 14:36:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Lua::Internal
|
|
|
|
|
|
|
|
#include "luaplugin.moc"
|