mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-22 02:19:44 +00:00
add app.get_stdin_stream
This commit is contained in:
parent
47b29da3f4
commit
6034c4933f
2 changed files with 25 additions and 2 deletions
|
|
@ -36,8 +36,9 @@ local function complete_app_lib(app)
|
||||||
local __app_set_setting = app.set_setting
|
local __app_set_setting = app.set_setting
|
||||||
local __app_quit = app.quit
|
local __app_quit = app.quit
|
||||||
local __app_get_stdout_stream = app.get_stdout_stream
|
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 io_stream = require "core:io_stream"
|
||||||
local stdout_stream_lib = {
|
local stdio_stream_lib = {
|
||||||
read = file.__read_descriptor,
|
read = file.__read_descriptor,
|
||||||
write = file.__write_descriptor,
|
write = file.__write_descriptor,
|
||||||
seek = file.__seek_descriptor,
|
seek = file.__seek_descriptor,
|
||||||
|
|
@ -53,7 +54,15 @@ local function complete_app_lib(app)
|
||||||
if descriptor == nil then
|
if descriptor == nil then
|
||||||
return nil
|
return nil
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
app.sleep = sleep
|
app.sleep = sleep
|
||||||
|
|
|
||||||
|
|
@ -429,6 +429,7 @@ static int l_start_background_instance(lua::State* L) {
|
||||||
"--sub-depth", std::to_string(engine->getCoreParameters()
|
"--sub-depth", std::to_string(engine->getCoreParameters()
|
||||||
.subProcessDepth + 1),
|
.subProcessDepth + 1),
|
||||||
"--log", io::resolve(outputPath).u8string(),
|
"--log", io::resolve(outputPath).u8string(),
|
||||||
|
"--stdin-cmd",
|
||||||
};
|
};
|
||||||
args.emplace_back("--project");
|
args.emplace_back("--project");
|
||||||
args.emplace_back(io::resolve(engine->getProject().path).u8string());
|
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);
|
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) {
|
static int l_get_stdout_stream(lua::State* L) {
|
||||||
int handle = lua::tointeger(L, 1);
|
int handle = lua::tointeger(L, 1);
|
||||||
if (handle < 0 || handle >= ::processes.size()) {
|
if (handle < 0 || handle >= ::processes.size()) {
|
||||||
|
|
@ -532,6 +545,7 @@ const luaL_Reg applib[] = {
|
||||||
{"start_background_instance", lua::wrap<l_start_background_instance>},
|
{"start_background_instance", lua::wrap<l_start_background_instance>},
|
||||||
{"is_instance_alive", lua::wrap<l_is_instance_alive>},
|
{"is_instance_alive", lua::wrap<l_is_instance_alive>},
|
||||||
{"terminate_instance", lua::wrap<l_terminate_instance>},
|
{"terminate_instance", lua::wrap<l_terminate_instance>},
|
||||||
|
{"get_stdin_stream", lua::wrap<l_get_stdin_stream>},
|
||||||
{"get_stdout_stream", lua::wrap<l_get_stdout_stream>},
|
{"get_stdout_stream", lua::wrap<l_get_stdout_stream>},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue