aboutsummaryrefslogtreecommitdiff
path: root/nerv/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'nerv/init.lua')
-rw-r--r--nerv/init.lua28
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')