forked from qt-creator/qt-creator
Lua: Move inspect and async into resources
Change-Id: I257323861823ed7858efdb265a78cc572c2e7273 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -612,11 +612,11 @@
|
||||
"QDocModule": "qtcreator",
|
||||
"QtParts": ["tools"],
|
||||
"QtUsage": "Used for async/await support in Lua modules.",
|
||||
"Path": "src/plugins/lua/bindings",
|
||||
"Path": "src/plugins/lua/scripts",
|
||||
"Description": "lua-async-await implements the async/await pattern in Lua.",
|
||||
"Homepage": "https://github.com/ms-jpq/lua-async-await",
|
||||
"License": "MIT License",
|
||||
"LicenseFile": "src/plugins/lua/bindings/ASYNC-LICENSE.txt",
|
||||
"LicenseFile": "src/plugins/lua/scripts/ASYNC-LICENSE.txt",
|
||||
"Copyright": "Copyright (c) 2008 Paul Evans"
|
||||
},
|
||||
{
|
||||
@@ -625,11 +625,11 @@
|
||||
"QDocModule": "qtcreator",
|
||||
"QtParts": ["tools"],
|
||||
"QtUsage": "Used for pretty printing from Lua scripts.",
|
||||
"Path": "share/qtcreator/lua-plugins/luatests",
|
||||
"Path": "src/plugins/lua/scripts",
|
||||
"Description": "inspect.lua is a library for pretty printing complex objects in Lua.",
|
||||
"Homepage": "https://github.com/kikito/inspect.lua",
|
||||
"License": "MIT License",
|
||||
"LicenseFile": "share/qtcreator/lua-plugins/luatests/INSPECT-LICENSE.txt",
|
||||
"LicenseFile": "src/plugins/lua/scripts/INSPECT-LICENSE.txt",
|
||||
"Copyright": "Copyright (c) 2022 Enrique García Cota"
|
||||
},
|
||||
{
|
||||
@@ -662,4 +662,3 @@
|
||||
"Copyright": "Copyright 2011 The Apache Software Foundation"
|
||||
}
|
||||
]
|
||||
|
||||
|
@@ -4,7 +4,6 @@ add_qtc_plugin(Lua
|
||||
PUBLIC_DEFINES LUA_AVAILABLE
|
||||
SOURCES
|
||||
bindings/action.cpp
|
||||
bindings/async.cpp
|
||||
bindings/async.h
|
||||
bindings/core.cpp
|
||||
bindings/fetch.cpp
|
||||
@@ -49,7 +48,9 @@ if(TARGET Lua)
|
||||
qt_add_resources(Lua lua_script_rcc
|
||||
PREFIX "/lua"
|
||||
FILES
|
||||
scripts/async.lua
|
||||
scripts/ilua.lua
|
||||
scripts/inspect.lua
|
||||
)
|
||||
|
||||
set_source_files_properties(luauibindings.cpp PROPERTY SKIP_AUTOMOC ON PROPERTY SKIP_AUTOGEN ON)
|
||||
|
@@ -39,7 +39,6 @@ QtcPlugin {
|
||||
|
||||
files: [
|
||||
"action.cpp",
|
||||
"async.cpp",
|
||||
"core.cpp",
|
||||
"fetch.cpp",
|
||||
"gui.cpp",
|
||||
|
@@ -171,6 +171,23 @@ void registerProvider(const QString &packageName, const PackageProvider &provide
|
||||
d->m_providers[packageName] = provider;
|
||||
}
|
||||
|
||||
void registerProvider(const QString &packageName, const FilePath &path)
|
||||
{
|
||||
registerProvider(packageName, [path](sol::state_view lua) -> sol::object {
|
||||
auto content = path.fileContents();
|
||||
if (!content)
|
||||
throw sol::error(content.error().toStdString());
|
||||
|
||||
sol::protected_function_result res
|
||||
= lua.script(content->data(), path.fileName().toStdString());
|
||||
if (!res.valid()) {
|
||||
sol::error err = res;
|
||||
throw err;
|
||||
}
|
||||
return res.get<sol::table>(0);
|
||||
});
|
||||
}
|
||||
|
||||
void autoRegister(const std::function<void(sol::state_view)> ®isterFunction)
|
||||
{
|
||||
d->m_autoProviders.append(registerFunction);
|
||||
|
@@ -51,6 +51,7 @@ LUA_EXPORT Utils::expected_str<sol::protected_function> prepareSetup(
|
||||
sol::state_view lua, const LuaPluginSpec &pluginSpec);
|
||||
|
||||
LUA_EXPORT void registerProvider(const QString &packageName, const PackageProvider &provider);
|
||||
LUA_EXPORT void registerProvider(const QString &packageName, const Utils::FilePath &path);
|
||||
LUA_EXPORT void autoRegister(const std::function<void(sol::state_view)> ®isterFunction);
|
||||
LUA_EXPORT void registerHook(
|
||||
QString name, const std::function<void(sol::function, QObject *guard)> &hookProvider);
|
||||
|
@@ -34,7 +34,6 @@ using namespace ExtensionSystem;
|
||||
namespace Lua::Internal {
|
||||
|
||||
void setupActionModule();
|
||||
void setupAsyncModule();
|
||||
void setupCoreModule();
|
||||
void setupFetchModule();
|
||||
void setupGuiModule();
|
||||
@@ -254,8 +253,10 @@ public:
|
||||
{
|
||||
setupLuaEngine(this);
|
||||
|
||||
registerProvider("async", ":/lua/scripts/async.lua");
|
||||
registerProvider("inspect", ":/lua/scripts/inspect.lua");
|
||||
|
||||
setupActionModule();
|
||||
setupAsyncModule();
|
||||
setupCoreModule();
|
||||
setupFetchModule();
|
||||
setupGuiModule();
|
||||
|
@@ -1,11 +1,3 @@
|
||||
// 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"
|
||||
|
||||
namespace Lua::Internal {
|
||||
|
||||
static const char *async_source = R"(
|
||||
-- From: https://github.com/ms-jpq/lua-async-await
|
||||
-- Licensed under MIT
|
||||
local co = coroutine
|
||||
@@ -70,13 +62,15 @@ end
|
||||
-- sugar over coroutine
|
||||
local await = function(defer)
|
||||
local _, isMain = coroutine.running()
|
||||
assert(not isMain, "a.wait was called outside of a running coroutine. You need to start one using a.sync(my_function)() first")
|
||||
assert(not isMain,
|
||||
"a.wait was called outside of a running coroutine. You need to start one using a.sync(my_function)() first")
|
||||
assert(type(defer) == "function", "type error :: expected func :: was: " .. type(defer))
|
||||
return co.yield(defer)
|
||||
end
|
||||
local await_all = function(defer)
|
||||
local _, isMain = coroutine.running()
|
||||
assert(not isMain, "a.wait_all was called outside of a running coroutine. You need to start one using a.sync(my_function)() first")
|
||||
assert(not isMain,
|
||||
"a.wait_all was called outside of a running coroutine. You need to start one using a.sync(my_function)() first")
|
||||
assert(type(defer) == "table", "type error :: expected table")
|
||||
return co.yield(join(defer))
|
||||
end
|
||||
@@ -86,14 +80,3 @@ return {
|
||||
wait_all = await_all,
|
||||
wrap = wrap,
|
||||
}
|
||||
)";
|
||||
|
||||
void setupAsyncModule()
|
||||
{
|
||||
registerProvider("async", [](sol::state_view lua) -> sol::object {
|
||||
sol::protected_function_result res = lua.script(async_source, "async.cpp");
|
||||
return res.get<sol::table>(0);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Lua::Internal
|
Reference in New Issue
Block a user