From 7fc533eb8f9f55ba83db256c811667c347e6bb1a Mon Sep 17 00:00:00 2001 From: cpuhrsch Date: Wed, 25 May 2016 17:33:39 +0200 Subject: [PATCH] Make CmdLine:log check whether file is a file descriptor, before creating a new file (#690) * Make CmdLine:log check whether file is a file descriptor, before creating a new file. --- CmdLine.lua | 2 +- doc/cmdline.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CmdLine.lua b/CmdLine.lua index d4f73fbd..23e99693 100644 --- a/CmdLine.lua +++ b/CmdLine.lua @@ -189,7 +189,7 @@ end local oprint = nil function CmdLine:log(file, params) - local f = io.open(file, 'w') + local f = (io.type(file) == 'file' and file) or io.open(file, 'w') oprint = oprint or print -- get the current print function lazily function print(...) local n = select("#", ...) diff --git a/doc/cmdline.md b/doc/cmdline.md index 7f34e28c..3f334397 100644 --- a/doc/cmdline.md +++ b/doc/cmdline.md @@ -107,7 +107,8 @@ The final produced output for the following command is: ### log(filename, parameter_table) ### It sets the log filename to `filename` and prints the values of -parameters in the `parameter_table`. +parameters in the `parameter_table`. If filename is an open file +descriptor, it will write to the file instead of creating a new one. ### option(name, default, help) ###