From 0c0ad6e7d85aa2bfc30dd3bdff3d4ba277e21790 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Thu, 13 Jun 2024 11:23:22 +0200 Subject: [PATCH] Lua: Replace -loadluaplugin with -pluginpath Change-Id: Ic398e09dedd6ba11a73e616788b92a001e0a96bd Reviewed-by: Eike Ziller --- src/plugins/lua/luaplugin.cpp | 49 +++------------------ src/plugins/lua/wizards/plugin/project.json | 2 +- src/plugins/lua/wizards/plugin/wizard.json | 8 +--- 3 files changed, 9 insertions(+), 50 deletions(-) diff --git a/src/plugins/lua/luaplugin.cpp b/src/plugins/lua/luaplugin.cpp index ec3007294f2..0290df988c3 100644 --- a/src/plugins/lua/luaplugin.cpp +++ b/src/plugins/lua/luaplugin.cpp @@ -49,24 +49,6 @@ public: } }; -struct Arguments -{ - std::optional loadPlugin; -}; - -Arguments parseArguments(const QStringList &arguments) -{ - Arguments args; - for (int i = 0; i < arguments.size() - 1; ++i) { - if (arguments.at(i) == QLatin1String("-loadluaplugin")) { - const QString path(arguments.at(i + 1)); - args.loadPlugin = FilePath::fromUserInput(path); - i++; // skip the argument - } - } - return args; -} - class LuaPlugin : public IPlugin { Q_OBJECT @@ -74,18 +56,15 @@ class LuaPlugin : public IPlugin private: std::unique_ptr m_luaEngine; - Arguments m_arguments; public: LuaPlugin() {} ~LuaPlugin() override = default; - bool initialize(const QStringList &arguments, QString *) final + void initialize() final { m_luaEngine.reset(new LuaEngine()); - m_arguments = parseArguments(arguments); - addAsyncModule(); addFetchModule(); addActionModule(); @@ -100,8 +79,6 @@ public: addInstallModule(); Core::JsExpander::registerGlobalObject("Lua", [] { return new LuaJsExtension(); }); - - return true; } bool delayedInitialize() final @@ -110,14 +87,17 @@ public: return true; } - void scanForPlugins(const FilePaths &paths) + void scanForPlugins(const FilePaths &pluginPaths) { QSet plugins; - for (const FilePath &path : paths) { + for (const FilePath &path : pluginPaths) { FilePaths folders = path.dirEntries(FileFilter({}, QDir::Dirs | QDir::NoDotAndDotDot)); for (const FilePath &folder : folders) { const FilePath script = folder / (folder.baseName() + ".lua"); + if (!script.exists()) + continue; + const expected_str result = m_luaEngine->loadPlugin(script); if (!result) { @@ -132,23 +112,6 @@ public: } } - if (m_arguments.loadPlugin) { - const FilePath folder = *m_arguments.loadPlugin; - const FilePath script = folder / (folder.baseName() + ".lua"); - const expected_str 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())); - - } else { - (*result)->setEnabledBySettings(true); - plugins.insert(*result); - } - } - PluginManager::addPlugins({plugins.begin(), plugins.end()}); PluginManager::loadPluginsAtRuntime(plugins); } diff --git a/src/plugins/lua/wizards/plugin/project.json b/src/plugins/lua/wizards/plugin/project.json index b7879f50d77..b13f0e967ff 100644 --- a/src/plugins/lua/wizards/plugin/project.json +++ b/src/plugins/lua/wizards/plugin/project.json @@ -9,7 +9,7 @@ "-tcs", "-load", "Lua", - "-loadluaplugin", + "-pluginpath", "%\{ActiveProject:ProjectDirectory\}" ] } diff --git a/src/plugins/lua/wizards/plugin/wizard.json b/src/plugins/lua/wizards/plugin/wizard.json index f854a49a3c1..b897f1eb141 100644 --- a/src/plugins/lua/wizards/plugin/wizard.json +++ b/src/plugins/lua/wizards/plugin/wizard.json @@ -19,10 +19,6 @@ "key": "ProjectFile", "value": "%{ProjectDirectory}/.qtcreator/project.json" }, - { - "key": "PluginNameLower", - "value": "%{JS: value('PluginName').toLowerCase()}" - }, { "key": "PluginSpecFile", "value": "%{JS: Util.fileName(value('PluginName').toLowerCase(), Util.preferredSuffix('text/x-lua'))}" @@ -147,14 +143,14 @@ }, { "source": "init.lua.tpl", - "target": "%{SrcFileName}" + "target": "%{PluginName}/%{SrcFileName}" }, { "source": ".luarc.json" }, { "source": "plugin.lua.tpl", - "target": "%{PluginSpecFile}", + "target": "%{PluginName}/%{PluginSpecFile}", "openInEditor": true } ]