forked from qt-creator/qt-creator
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user