Merge pull request #965 from MihailRis/update-headless-sub-instances

add project arguments table passing in app.start_background_instance
This commit is contained in:
MihailRis 2026-09-03 22:58:48 +03:00 • committed by GitHub
commit c2a77509f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 2 deletions

View file

@ -172,7 +172,9 @@ app.start_background_instance(
-- script file
app_script: string,
-- log file
output_file: string | nil
output_file: string,
-- project parameters (can be read with vc.get_project_arg(name))
project_args: table<string, string> | nil
) -> int
-- Checks if the engine sub-instance is alive.

View file

@ -162,7 +162,9 @@ app.start_background_instance(
-- файл сценария
app_script: string,
-- файл лога
output_file: string | nil
output_file: string,
-- параметры проекта, что будут доступны через vc.get_project_arg(name)
project_args: table<string, string> | nil,
) -> int
-- Проверяет, жив ли под-экземпляр движка.

View file

@ -405,6 +405,20 @@ static int l_start_background_instance(lua::State* L) {
auto scriptPath = lua::require_lstring(L, 1);
io::path outputPath = lua::isstring(L, 2) ? lua::require_lstring(L, 2) : "";
std::vector<std::pair<std::string, std::string>> projectArgs;
if (lua::istable(L, 3)) {
lua::pushnil(L);
while (lua::next(L, 3)) {
lua::pushvalue(L, -2);
auto key = lua::tolstring(L, -1);
auto value = lua::tolstring(L, -2);
projectArgs.emplace_back(key, value);
lua::pop(L, 2);
}
lua::pop(L);
}
const auto& paths = engine->getPaths();
std::vector<std::string> args {
@ -419,6 +433,17 @@ static int l_start_background_instance(lua::State* L) {
args.emplace_back("--project");
args.emplace_back(io::resolve(engine->getProject().path).u8string());
if (!projectArgs.empty()) {
args.emplace_back("--");
for (const auto& [key, value] : projectArgs) {
if (key.empty()) {
throw std::runtime_error("empty project argument name passed");
}
args.emplace_back("--" + key);
args.emplace_back(value);
}
}
int handle = -1;
for (int i = 0; i < ::processes.size(); i++) {
if (!::processes[i] || !::processes[i]->isActive()) {