lua-users home
lua-l archive

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

> My suggestion for adding lua_stdout and lua_stderr allows you to redefine
> stdout and stderr at runtime if you dont have the advantage of being able
> redirect these streams. eg. in Windows. You may want to do this for
> if you use Lua to load some kind of debug library at runtime which catches
> stderr. I realise I can edit the Lua code but it would be nice if this
> the default functionality.

>> Can't the lua library function "writeto" be used to change stdout at
runtime?  I don't know about stderr though...

The manual says (sect 6.4) you can redirect _OUTPUT into a given file using
writeto(filename). Errors, or stderr, can be caught by redefining the
_ALERT() function. It would be nice to be able to redirect stdout as you can
stderr (using _ALERT) something like _WRITE(text). I dont think you can do
that? (Sorry I'm still a learner) You actually have to alter Lua code to do
this. So with a standard installation of Lua I could do:

lua_dostring(state,"_WRITE,_ALERT = mywrite,myalert");

and all my output is redirected to my handlers.

The changes I suggested before would allow you to do the same thing in code
but all calls to stdout and stderr would have to been done through the
lua_stdout & lua_stderr functions. This could make the above quite easy to

Do this make any sense! Maybe I just need to get into more of a Lua
mindset?!! :-)