Lua: Add Lua plugin support

Adds basic support for writing Plugins using the lua scripting language.
Lua Plugins are registered just as native plugins are and can be enabled
or disabled via the plugin dialog.

see src/plugins/lua/README.md for further details.

Change-Id: I9f4d15e9632c46e1c6c132bcd0bbcdd70b150640
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-04-12 14:36:37 +02:00
parent a296157f58
commit 6e3aab5f1b
49 changed files with 4301 additions and 1 deletions

View File

@@ -0,0 +1,65 @@
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "../luaengine.h"
#include <coreplugin/editormanager/editormanager.h>
namespace Lua {
class Hook : public QObject
{
Q_OBJECT
public:
Hook(QObject *source);
signals:
void trigger(sol::table &args);
};
Hook::Hook(QObject *source)
: QObject(source)
{}
namespace Internal {
void addHookModule()
{
LuaEngine::autoRegister([](sol::state_view lua) {
auto connection = lua.new_usertype<QMetaObject::Connection>("QMetaConnection",
sol::no_constructor);
auto hook = lua.new_usertype<Hook>(
"Hook",
sol::no_constructor,
"connect",
[](Hook *hook, sol::function func) -> QMetaObject::Connection {
QMetaObject::Connection con
= QObject::connect(hook, &Hook::trigger, [func](sol::table args) {
auto res = LuaEngine::void_safe_call(func, args);
QTC_CHECK_EXPECTED(res);
});
return con;
},
"disconnect",
[](Hook *, QMetaObject::Connection con) { QObject::disconnect(con); });
});
LuaEngine::registerHook("editors.documentOpened", [](sol::function func) {
QObject::connect(Core::EditorManager::instance(),
&Core::EditorManager::documentOpened,
[func](Core::IDocument *document) { func(document); });
});
LuaEngine::registerHook("editors.documentClosed", [](sol::function func) {
QObject::connect(Core::EditorManager::instance(),
&Core::EditorManager::documentClosed,
[func](Core::IDocument *document) { func(document); });
});
}
} // namespace Internal
} // namespace Lua
#include "hook.moc"