Lua: Add Install module

Allows plugins to install packages they might need.

Change-Id: I4948dd0a6568e093fc35e4486d2e2a084090e103
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-05-14 13:47:50 +02:00
parent f54a83ff45
commit eec48b8f8e
9 changed files with 482 additions and 25 deletions

View File

@@ -5,6 +5,7 @@
#include "luapluginspec.h"
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <utils/algorithm.h>
@@ -13,6 +14,7 @@
#include <QJsonArray>
#include <QJsonObject>
#include <QStandardPaths>
using namespace Utils;
@@ -151,6 +153,16 @@ expected_str<void> LuaEngine::prepareSetup(
const QString searchPath = (pluginSpec.location() / "?.lua").toUserOutput();
lua["package"]["path"] = searchPath.toStdString();
const FilePath appDataPath = Core::ICore::userResourcePath() / "plugin-data" / "lua"
/ pluginSpec.location().fileName();
sol::environment env(lua, sol::create, lua.globals());
lua.new_usertype<ScriptPluginSpec>(
"PluginSpec", sol::no_constructor, "name", sol::readonly(&ScriptPluginSpec::name));
lua["PluginSpec"] = ScriptPluginSpec{pluginSpec.name(), appDataPath};
// TODO: only register what the plugin requested
for (const auto &[name, func] : d->m_providers.asKeyValueRange()) {
lua["package"]["preload"][name.toStdString()] = [func = func](const sol::this_state &s) {