[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Extending the io library
- From: Thomas Lauer <thomas.lauer@...>
- Date: Thu, 17 Jul 2008 10:37:09 +0100
"Paul Moore" <email@example.com> wrote:
> I have an application with Lua embedded, which exposes the io library.
> However, there are some issues with the standard streams. My
> application has C stdin/stdout/stderr available, but they are
> inappropriate (for reasons which I can explain if needed, but are
> probably not relevant here). This is easy to resolve, as I can just
> delete the io.stdin, io.stdout and io.stderr variables.
> However, I also have some other file pointers (technically, Windows OS
> handles, but I can easily wrap them in a FILE*) which *are*
> appropriate as stdin/out/err. I would like to expose them via the io
> library, but I don't see an easy way to do this, as there is no C API
> to create an io object from a FILE*.
> I see two ways of proceeding:
> 1. Modify the C code for the io library to expose a constructor from a
> FILE*. I'd rather avoid this, as having a customised Lua interpreter
> adds complexity I'd like to avoid to my build environment. (Plus, it
> potentially makes my interpreter incompatible with existing loadable
> 2. Write a wrapper class which mimics io objects, and use that. That's
> a real pain, as I'm basically reimplementing the io library for a
> couple of minor convenience features.
> If I have no other option, I'll probably go with (1), or simply not
> bother exposing the other handles. But if anyone can suggest a third
> option I've missed, I would be extremely grateful.
Why not set Lua's io.std* variables from your C code? You can do so
inside Lua code and (given the right massaging) you can do the same from
C. At least that's what I did (and you know for what;-)) and it seems to
However, I'd have to agree that this issue needs some attention in
future versions of Lua. For something that's expressly designed to be
embeddable I think this lack of interoperability is surprising.
Same goes for the issue summarised in the "interpreter bailout thread".