lua-users home
lua-l archive

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


On 21 June 2018 at 17:22, Niccolo Medici <niccolomedici@gmail.com> wrote:
> I want to redirect the output of print() to a file of my choosing.
>
> (I know I can do "$ lua program.lua > output.txt", but I need to
> create several output files. My program is already written and I don't
> want to modify it too much.)

You could re-implement print() at the start of your program, something
like this:

function print(...)
        local n_param = select("#", ...);
        for i = 1, n_param do
                io.write(tostring((select(i, ...))), i<n_param and
"\t" or "\n");
        end
end

Regards,
Matthew