lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 15.08.13 15:55, Aaron B. wrote:
On Thu, 15 Aug 2013 10:08:55 +0200
steve donovan <steve.j.donovan@gmail.com> wrote:

Nice and very doable, I've been thinking about this. Generally people pick
a platform and use the appropriate native API, but it _is_ useful to have
cross-platform scripting that hides some implementation details.

I've thought about this as well.

It would also be nice to have it be compatible with, or include a
compatibility layer with, the LuaSocket API.

I've got a program that talks to both the network and to spawned
processes. It would be much cleaner to handle all the IO via Copas.

And this is the hidden problem. On Windows pipes (and anything else you may wish to use) will not work with select. Passing sockets as stdin/stdout/stderr (after you implement socketpair) may work but AFAIR only if you have a simple enough child. If it tries to be clever and do overlapped IO on stdio (which is the only way to work asynchronously with the terminal window without using threads) it will fail because sockets have to be created differently for OVERLAPPED and non-OVERLAPPED use. In my own programs I special-case stdin and run a thread doing blocking reads and passing the result over a socket. This is the only way I know of that works with both pipes and normal terminals.

For cross-platform bidir communication in Lua I open a listening socket in the parent and have this child manually connect to it (this of course requires a cooperating child).

There is a separate issue of killing the child and of handling open files inheritance (fopen gives inheritable files by default and popen cannot do better than just pass them to the child).


I sometimes think that the only sane way to do it universally would be to use libuv on Windows since they take great care to do everything via IO completion ports (which is a yet another (4th?) method of doing IO on Windows).

--
regards,
Jakub Piotr Cłapa
LoEE.pl