lua-users home
lua-l archive

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


On 11/02/2013 08:53 AM, Peng Zhicheng wrote:
于 2013-10-31 21:23, Leo Razoumov 写道:
Patching Lua source to achive output redirection looks like overkill to me. --Leo--

Me too.

And I feel that **even if** you decide that a patch is appropriate for your application,
a (maybe) more natual way is to patch the baselib(for 'print') and/or iolib(for 'std.out',
'std.err', etc), instead of adding new hooks(??dependency injection) into the lua_State.
Ok, i must agree on this point.



I think an allocator is crucial to the core engine of Lua, while IO is not.

Anyway, I suggest the "io.output(redirected_output_file)" solution.

Or, maybe 'freopen()'(for ANSI C) or 'SetStdHandle()'(for Windows)
or combination of 'close()' and 'open()' (for POSIX) woudl also help.
I can't reopen or dup the standard outputs for my process. I use stdout and stderr for other purposes.

I'm looking for the best solution to redirect outputs to a socket stream. Till now, the ml gave me several solutions :
 - redirect to a file (io.output(redirected_output_file)), i'm not sure that is a solution for this problem
 - redefine print (_G.print = myprint), i like this one and i'm currently trying to understand how to pass userdata (closures seems to be the solution, but i hardly understand how to use it from c)
 - patch sources, seems to be excluded...

Thank you for your help and suggestions.

Paul