Lua: Add connection guard

Improves safety by limiting connection lifetime to
lifetime of lua vm.

Change-Id: I508b0814fdda169f5e30d7c3282132e3c622a0a5
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-05-28 12:35:25 +02:00
parent 26cfa86969
commit b9f2808384
7 changed files with 78 additions and 71 deletions

View File

@@ -156,14 +156,13 @@ expected_str<void> LuaEngine::prepareSetup(
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::property([](ScriptPluginSpec &self) {
return self.name;
}));
lua["PluginSpec"] = ScriptPluginSpec{pluginSpec.name(), appDataPath};
lua["PluginSpec"]
= ScriptPluginSpec{pluginSpec.name(), appDataPath, std::make_unique<QObject>()};
// TODO: only register what the plugin requested
for (const auto &[name, func] : d->m_providers.asKeyValueRange()) {