forked from qt-creator/qt-creator
Lua: Fix soft loading
Previously the LuaEngine::loadPlugin() function tried to fully setup the lua interpreter. This was called before the dependencies of a lua plugin were fully soft loaded. Therefore the dependent lua packages had not been registered yet. This patch changes that to where the packages and lua libraries are only loaded right before the actual setup call is done. This also allows us to safely load the plugin spec without giving it access to all the functionality directly. In the future we could show and ask the user before we load the plugin whether he agrees to give it the requested access. Change-Id: Ibf3e81db54e2ba94473e8ecf2650dcf2e97f1360 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -94,14 +94,15 @@ bool LuaPluginSpec::loadLibrary()
|
||||
}
|
||||
bool LuaPluginSpec::initializePlugin()
|
||||
{
|
||||
std::optional<sol::table> hookTable = d->pluginTable.get<std::optional<sol::table>>("hooks");
|
||||
if (hookTable) {
|
||||
auto res = LuaEngine::connectHooks(d->lua, *hookTable);
|
||||
if (!res) {
|
||||
setError(Lua::Tr::tr("Failed to connect hooks: %1").arg(res.error()));
|
||||
return false;
|
||||
}
|
||||
expected_str<void> setupResult
|
||||
= LuaEngine::instance()
|
||||
.prepareSetup(d->lua, *this, d->pluginTable.get<sol::optional<sol::table>>("hooks"));
|
||||
|
||||
if (!setupResult) {
|
||||
setError(Lua::Tr::tr("Failed to prepare plugin setup: %1").arg(setupResult.error()));
|
||||
return false;
|
||||
}
|
||||
|
||||
auto result = d->setupFunction.call();
|
||||
|
||||
if (result.get_type() == sol::type::boolean && result.get<bool>() == false) {
|
||||
|
||||
Reference in New Issue
Block a user