forked from qt-creator/qt-creator
Lua: Add -loadluaplugin startup argument
Change-Id: Ia0a57bbb94d42534857889a0d08ec41c75708dca Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -17,5 +17,13 @@
|
|||||||
"Category" : "Scripting",
|
"Category" : "Scripting",
|
||||||
"Description" : "Support for Lua based plugins.",
|
"Description" : "Support for Lua based plugins.",
|
||||||
"Url" : "https://www.qt.io",
|
"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}
|
${IDE_PLUGIN_DEPENDENCIES}
|
||||||
}
|
}
|
||||||
|
@@ -49,6 +49,24 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Arguments
|
||||||
|
{
|
||||||
|
std::optional<FilePath> 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
|
class LuaPlugin : public IPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -56,15 +74,18 @@ class LuaPlugin : public IPlugin
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<LuaEngine> m_luaEngine;
|
std::unique_ptr<LuaEngine> m_luaEngine;
|
||||||
|
Arguments m_arguments;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LuaPlugin() {}
|
LuaPlugin() {}
|
||||||
~LuaPlugin() override = default;
|
~LuaPlugin() override = default;
|
||||||
|
|
||||||
void initialize() final
|
bool initialize(const QStringList &arguments, QString *) final
|
||||||
{
|
{
|
||||||
m_luaEngine.reset(new LuaEngine());
|
m_luaEngine.reset(new LuaEngine());
|
||||||
|
|
||||||
|
m_arguments = parseArguments(arguments);
|
||||||
|
|
||||||
addAsyncModule();
|
addAsyncModule();
|
||||||
addFetchModule();
|
addFetchModule();
|
||||||
addActionModule();
|
addActionModule();
|
||||||
@@ -79,6 +100,8 @@ public:
|
|||||||
addInstallModule();
|
addInstallModule();
|
||||||
|
|
||||||
Core::JsExpander::registerGlobalObject("Lua", [] { return new LuaJsExtension(); });
|
Core::JsExpander::registerGlobalObject("Lua", [] { return new LuaJsExtension(); });
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool delayedInitialize() final
|
bool delayedInitialize() final
|
||||||
@@ -94,8 +117,7 @@ public:
|
|||||||
{
|
{
|
||||||
QSet<PluginSpec *> plugins;
|
QSet<PluginSpec *> plugins;
|
||||||
for (const FilePath &path : paths) {
|
for (const FilePath &path : paths) {
|
||||||
const FilePaths folders = path.dirEntries(
|
FilePaths folders = path.dirEntries(FileFilter({}, QDir::Dirs | QDir::NoDotAndDotDot));
|
||||||
FileFilter({}, QDir::Dirs | QDir::NoDotAndDotDot));
|
|
||||||
|
|
||||||
for (const FilePath &folder : folders) {
|
for (const FilePath &folder : folders) {
|
||||||
const FilePath script = folder / (folder.baseName() + ".lua");
|
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<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()));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
(*result)->setEnabledBySettings(true);
|
||||||
|
plugins.insert(*result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PluginManager::addPlugins({plugins.begin(), plugins.end()});
|
PluginManager::addPlugins({plugins.begin(), plugins.end()});
|
||||||
PluginManager::loadPluginsAtRuntime(plugins);
|
PluginManager::loadPluginsAtRuntime(plugins);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user