diff --git a/src/plugins/lua/Lua.json.in b/src/plugins/lua/Lua.json.in index c41ce7bc88c..68b54fd1add 100644 --- a/src/plugins/lua/Lua.json.in +++ b/src/plugins/lua/Lua.json.in @@ -17,5 +17,13 @@ "Category" : "Scripting", "Description" : "Support for Lua based plugins.", "Url" : "https://www.qt.io", + "JsonWizardPaths" : [":/lua/wizards"], + "Arguments" : [ + { + "Name" : "-loadluaplugin", + "Parameter" : "path", + "Description" : "Load an additional lua plugin from the specified path" + } + ], ${IDE_PLUGIN_DEPENDENCIES} } diff --git a/src/plugins/lua/luaplugin.cpp b/src/plugins/lua/luaplugin.cpp index 93d48ff6cf8..60505ade850 100644 --- a/src/plugins/lua/luaplugin.cpp +++ b/src/plugins/lua/luaplugin.cpp @@ -49,6 +49,24 @@ 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 @@ -56,15 +74,18 @@ class LuaPlugin : public IPlugin private: std::unique_ptr m_luaEngine; + Arguments m_arguments; public: LuaPlugin() {} ~LuaPlugin() override = default; - void initialize() final + bool initialize(const QStringList &arguments, QString *) final { m_luaEngine.reset(new LuaEngine()); + m_arguments = parseArguments(arguments); + addAsyncModule(); addFetchModule(); addActionModule(); @@ -79,6 +100,8 @@ public: addInstallModule(); Core::JsExpander::registerGlobalObject("Lua", [] { return new LuaJsExtension(); }); + + return true; } bool delayedInitialize() final @@ -94,8 +117,7 @@ public: { QSet plugins; for (const FilePath &path : paths) { - const FilePaths folders = path.dirEntries( - FileFilter({}, QDir::Dirs | QDir::NoDotAndDotDot)); + FilePaths folders = path.dirEntries(FileFilter({}, QDir::Dirs | QDir::NoDotAndDotDot)); for (const FilePath &folder : folders) { const FilePath script = folder / (folder.baseName() + ".lua"); @@ -113,6 +135,23 @@ 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); }