[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Redirecting stdin/stdout
- From: Daurnimator <quae@...>
- Date: Sat, 26 Mar 2016 02:09:06 +1100
On 25 March 2016 at 22:26, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> Hi
>
> I am working on implementing a debug adapter for Lua/Ravi for VSCode.
> The way VSCode interacts with the adapter is via stdin/stdout. So I
> have two options for interacting with the Lua VM:
>
> a) VSCode launches the Debug Adapter (as a process) which then
> launches Lua as another separate process and communicates with Lua
> over TCP/IP (similar to MobDebug).
>
> b) VSCode launches the Debug Adapter (as a process) which then runs
> Lua in-process.
>
> I prefer b) for now, eventually I may also look at a). But in order to
> implement b) I need to get Lua to avoid reading/writing from
> stdin/stdout directly. So I am thinking of adding fields in lua_State
> that will hold stdin/stdout file descriptors that Lua should use - so
> that I can set these to alternative file descriptors. I would like to
> redirect Lua's stdout to a file, while the real stdout is taken over
> by the debug adapter. Similarly Lua's stdin will read from a file,
> while the real stdin is read by the debug adapter.
>
> Has anyone done a similar redirection exercise before?
>
> Regards
> Dibyendu
>
See the lua standard lib functions `io.input` and `io.output`. Then
check out their C implementation if you must....