diff options
author | Determinant <[email protected]> | 2016-03-03 15:49:10 +0800 |
---|---|---|
committer | Determinant <[email protected]> | 2016-03-03 15:49:10 +0800 |
commit | e1c004f89ec3a783cf1948165baae5975489f775 (patch) | |
tree | f6b630853eac2719ef290d5bb8b7573e4f2c8567 /nerv/init.lua | |
parent | c964d74b1927ffd9fd431f457f7e385b2d2ba5ba (diff) |
add Penlight to facilitate file copying and dir making
Diffstat (limited to 'nerv/init.lua')
-rw-r--r-- | nerv/init.lua | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/nerv/init.lua b/nerv/init.lua index a5b032c..06cb611 100644 --- a/nerv/init.lua +++ b/nerv/init.lua @@ -13,6 +13,10 @@ function nerv.error_method_not_implemented() nerv.error("method not implemented"); end +function nerv.set_logfile(filename) + nerv._logfile = io.open(filename, "w") +end + --- Format a string just like `sprintf` in C. -- @param fmt the format string -- @param ... args, the data to be formatted @@ -25,7 +29,13 @@ end -- @param fmt the format string -- @param ... args, the data to be formatted function nerv.printf(fmt, ...) - io.stderr:write(nerv.sprintf(fmt, ...)) + local line = nerv.sprintf(fmt, ...) + io.stderr:write(line) + -- duplicate the all output to the log file, if set + if nerv._logfile then + nerv._logfile:write(line) + nerv._logfile:flush() + end end --- Raise an global error with the formatted message. @@ -328,6 +338,22 @@ function nerv.print_usage(options) nerv.printf("\n") end +-- function nerv.copy_file(fname1, fname2) +-- local fin, fout, err +-- fin, err = io.open(fname1, "r") +-- if fin then +-- fout, err = io.open(fname2, "w") +-- end +-- if not (fin and fout) then +-- nerv.error("[copy] from %s to %s: %s", fname1, fname2, err) +-- end +-- while true do +-- local b = fin:read(1024) +-- if b == nil then break end +-- fout:write(b) +-- end +-- end + -- the following lines trigger the initialization of basic modules nerv.include('matrix/init.lua') |