[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Extending the io library
- From: "Paul Moore" <p.f.moore@...>
- Date: Thu, 17 Jul 2008 10:12:23 +0100
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.