[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Redirecting stdin/stdout
- From: 书呆彭, Peng Yi <nerditation@...>
- Date: Mon, 28 Mar 2016 08:56:13 +0800
在 2016/3/25 19:26, Dibyendu Majumdar 写道:
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
I don't think lua_State is the right place to put that information. the core Lua engine does no IO
at all. the lua_newstate function only takes a allocator. it is the library and the interpreter
program which deal with IO. so IMO you should really change the baselib instead.
I am not aware of the VSCode adapter protocol. does it use native Windows HANDLE or the CRT file descriptor?
you might be interested in these functions: GetStdHandle, SetStdHandle, _get_osfhandle, _open_osfhandle
--
the nerdy Peng / 书呆彭 / Sent from Thunderbird