From 6034c4933faa1aaed0a303fc7e17fa0c6fa5fe01 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 12 Oct 2026 03:05:25 +0300 Subject: [PATCH] add app.get_stdin_stream --- res/scripts/stdlib.lua | 13 +++++++++++-- src/logic/scripting/lua/libs/libapp.cpp | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 0deb5c2d8..ebb057573 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -36,8 +36,9 @@ local function complete_app_lib(app) local __app_set_setting = app.set_setting local __app_quit = app.quit local __app_get_stdout_stream = app.get_stdout_stream + local __app_get_stdin_stream = app.get_stdin_stream local io_stream = require "core:io_stream" - local stdout_stream_lib = { + local stdio_stream_lib = { read = file.__read_descriptor, write = file.__write_descriptor, seek = file.__seek_descriptor, @@ -53,7 +54,15 @@ local function complete_app_lib(app) if descriptor == nil then return nil end - return io_stream.new(descriptor, false, stdout_stream_lib) + return io_stream.new(descriptor, false, stdio_stream_lib) + end + + app.get_stdin_stream = function(handle) + local descriptor = __app_get_stdin_stream(handle) + if descriptor == nil then + return nil + end + return io_stream.new(descriptor, false, stdio_stream_lib) end app.sleep = sleep diff --git a/src/logic/scripting/lua/libs/libapp.cpp b/src/logic/scripting/lua/libs/libapp.cpp index cc7faec9b..9e6b520eb 100644 --- a/src/logic/scripting/lua/libs/libapp.cpp +++ b/src/logic/scripting/lua/libs/libapp.cpp @@ -429,6 +429,7 @@ static int l_start_background_instance(lua::State* L) { "--sub-depth", std::to_string(engine->getCoreParameters() .subProcessDepth + 1), "--log", io::resolve(outputPath).u8string(), + "--stdin-cmd", }; args.emplace_back("--project"); args.emplace_back(io::resolve(engine->getProject().path).u8string()); @@ -483,6 +484,18 @@ static int l_terminate_instance(lua::State* L) { return lua::pushboolean(L, active); } +static int l_get_stdin_stream(lua::State* L) { + int handle = lua::tointeger(L, 1); + if (handle < 0 || handle >= ::processes.size()) { + throw std::runtime_error("invalid process handle"); + } + auto& process = ::processes[handle]; + if (process == nullptr) { + return 0; + } + return lua::pushinteger(L, process->getStdinDescriptor()); +} + static int l_get_stdout_stream(lua::State* L) { int handle = lua::tointeger(L, 1); if (handle < 0 || handle >= ::processes.size()) { @@ -532,6 +545,7 @@ const luaL_Reg applib[] = { {"start_background_instance", lua::wrap}, {"is_instance_alive", lua::wrap}, {"terminate_instance", lua::wrap}, + {"get_stdin_stream", lua::wrap}, {"get_stdout_stream", lua::wrap}, {nullptr, nullptr} };