lua-users home
lua-l archive

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


于 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.


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.