From 50b1bcbd64f2794868e66652ea0803896c3f1941 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Sun, 9 Jun 2024 16:22:47 +0530 Subject: [PATCH] fix: stop accepting stdio options for process.spawn --- crates/lune-std-process/src/lib.rs | 7 +++++-- test.lua | 16 ++++++++++++++++ types/process.luau | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 test.lua diff --git a/crates/lune-std-process/src/lib.rs b/crates/lune-std-process/src/lib.rs index cc88cce..f9cb7b5 100644 --- a/crates/lune-std-process/src/lib.rs +++ b/crates/lune-std-process/src/lib.rs @@ -15,6 +15,7 @@ use mlua::prelude::*; use lune_utils::TableBuilder; use mlua_luau_scheduler::{Functions, LuaSpawnExt}; +use options::ProcessSpawnOptionsStdio; use os_str_bytes::RawOsString; use stream::{ChildProcessReader, ChildProcessWriter}; use tokio::{io::AsyncWriteExt, process::Child}; @@ -183,8 +184,10 @@ async fn process_spawn( lua: &Lua, (program, args, options): (String, Option>, ProcessSpawnOptions), ) -> LuaResult { + // Spawn does not accept stdio options, so we remove them from the options + // and use the defaults instead let mut spawn_options = options.clone(); - spawn_options.stdio.stdin = None; + spawn_options.stdio = ProcessSpawnOptionsStdio::default(); let (stdin_tx, stdin_rx) = tokio::sync::oneshot::channel(); let (stdout_tx, stdout_rx) = tokio::sync::oneshot::channel(); @@ -221,7 +224,7 @@ async fn process_spawn( .expect("ExitCode receiver was unexpectedly dropped"); }); - // TODO: If not piped, don't return readers and writers instead of panicking + // TODO: Remove the lua errors since we no longer accept stdio options for spawn TableBuilder::new(lua)? .with_value( "stdout", diff --git a/test.lua b/test.lua new file mode 100644 index 0000000..fa5e8ab --- /dev/null +++ b/test.lua @@ -0,0 +1,16 @@ +local process = require("@lune/process") +local stdio = require("@lune/stdio") + +local child = process.spawn("luau-lsp", { "lsp" }) + +while true do + child.stdin:write("hello world") + local buf = child.stdout:read() + + if buffer.len(buf) == 0 then + break + end + + stdio.write(buffer.tostring(buf) .. "\n") + -- stdio.write(buffer.tostring(child.stderr:read() .. child.stderr:read() .. child.stderr:read() .. child.stderr:read())) +end \ No newline at end of file diff --git a/types/process.luau b/types/process.luau index d6924cd..5fd2e8b 100644 --- a/types/process.luau +++ b/types/process.luau @@ -26,7 +26,6 @@ export type SpawnOptions = { cwd: string?, env: { [string]: string }?, shell: (boolean | string)?, - stdio: (SpawnOptionsStdio | SpawnOptionsStdioKind)?, } --[=[ @@ -42,6 +41,7 @@ export type SpawnOptions = { * `stdin` - Optional standard input to pass to executed child process ]=] export type ExecuteOptions = SpawnOptions & { + stdio: (SpawnOptionsStdio | SpawnOptionsStdioKind)?, stdin: string?, -- TODO: Remove this since it is now available in stdio above, breaking change }