forked from qt-creator/qt-creator
Lua: Replace -loadluaplugin with -pluginpath
Change-Id: Ic398e09dedd6ba11a73e616788b92a001e0a96bd Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -49,24 +49,6 @@ 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
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -74,18 +56,15 @@ class LuaPlugin : public IPlugin
|
||||
|
||||
private:
|
||||
std::unique_ptr<LuaEngine> 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<PluginSpec *> 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<LuaPluginSpec *> 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<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::loadPluginsAtRuntime(plugins);
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
"-tcs",
|
||||
"-load",
|
||||
"Lua",
|
||||
"-loadluaplugin",
|
||||
"-pluginpath",
|
||||
"%\{ActiveProject:ProjectDirectory\}"
|
||||
]
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
]
|
||||
|
Reference in New Issue
Block a user