Lua: Add onFinished callback to Process class

Change-Id: I98645f9d33842eb16b80e768523d63d660fe1813
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Justyna Hudziak
2024-09-27 14:54:24 +02:00
parent 1be3449407
commit 47a0f935ba
2 changed files with 12 additions and 0 deletions

View File

@@ -60,6 +60,7 @@ void setupProcessModule()
const auto stdOut = parameter.get<std::optional<sol::function>>("stdout");
const auto stdErr = parameter.get<std::optional<sol::function>>("stderr");
const auto stdIn = parameter.get<sol::optional<QString>>("stdin");
const auto onFinished = parameter.get<std::optional<sol::function>>("onFinished");
auto p = std::make_unique<Process>();
@@ -86,6 +87,16 @@ void setupProcessModule()
});
// clang-format on
}
if (onFinished) {
// clang-format off
QObject::connect(p.get(), &Process::done,
p.get(),
[p = p.get(), cb = *onFinished]() {
void_safe_call(cb);
});
// clang-format on
}
return p;
};

View File

@@ -24,6 +24,7 @@ process.Process = {}
---@field stdin? string The input to write to stdin.
---@field stdout? function The callback to call when the process writes to stdout.
---@field stderr? function The callback to call when the process writes to stderr.
---@field onFinished? function () The callback to call when the process finishes.
process.ProcessParameters = {}
---Creates a new process object.