add app.get_stdout_stream

This commit is contained in:
MihailRis 2026-10-11 22:23:48 +03:00
parent 0cacd1f670
commit 0340e2977e
2 changed files with 34 additions and 0 deletions

View file

@ -35,6 +35,26 @@ local function complete_app_lib(app)
local __app_tick = coroutine.yield
local __app_set_setting = app.set_setting
local __app_quit = app.quit
local __app_get_stdout_stream = app.get_stdout_stream
local io_stream = require "core:io_stream"
local stdout_stream_lib = {
read = file.__read_descriptor,
write = file.__write_descriptor,
seek = file.__seek_descriptor,
tell = file.__tell_descriptor,
flush = file.__flush_descriptor,
available = file.__available_descriptor,
is_alive = file.__has_descriptor,
close = file.__close_descriptor,
}
app.get_stdout_stream = function(handle)
local descriptor = __app_get_stdout_stream(handle)
if descriptor == nil then
return nil
end
return io_stream.new(descriptor, false, stdout_stream_lib)
end
app.sleep = sleep
app.script = __VC_SCRIPT_NAME

View file

@ -483,6 +483,18 @@ static int l_terminate_instance(lua::State* L) {
return lua::pushboolean(L, active);
}
static int l_get_stdout_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->getStdoutDescriptor());
}
const luaL_Reg applib[] = {
/// content
{"is_content_loaded", lua::wrap<l_is_content_loaded>},
@ -515,9 +527,11 @@ const luaL_Reg applib[] = {
/// other
{"get_version", lua::wrap<l_get_version>},
{"create_memory_device", lua::wrap<l_create_memory_device>},
// sub-instances
{"start_debug_instance", lua::wrap<l_start_debug_instance>},
{"start_background_instance", lua::wrap<l_start_background_instance>},
{"is_instance_alive", lua::wrap<l_is_instance_alive>},
{"terminate_instance", lua::wrap<l_terminate_instance>},
{"get_stdout_stream", lua::wrap<l_get_stdout_stream>},
{nullptr, nullptr}
};