lua-users home
lua-l archive

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


I have an application into which I want to embed Lua. However, the application does some (quite legitimate) manipulation of the Windows standard handles (STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE). As a result, although the concepts of stdin/out/err are completely legitimate, the C stdin/out/err file handles don't point to the right place.

What I'd like to do is to make the Lua concept of standard IO point at different (FILE *)'s, in such a way that all Lua IO (print, io.stdin, error messages, etc, etc) goes to my own handles. Is there a way of doing this?

So, I'd have for example:

    FILE *my_stdin = /* something appropriate here */;
    FILE *my_stdout = /* something appropriate here */;
    FILE *my_stderr = /* something appropriate here */;

    lua_RedirectIO(my_stdin, my_stdout, my_stderr);

I specifically don't want to overwrite (in particular, close) the original stdin/out/err, as that causes other issues with the hosting application.

Oddly, it appears that io.output() doesn't affect print, otherwise that would be an option. Maybe I could set io.output and override print - but how can I be sure I've caught everything?

Can anyone offer any suggestions? I've searched the mailing list archives, and was surprised to find no hints there.

Thanks,
Paul.