A bit of clean-up on io.lua
This commit is contained in:
parent
ffdacd7fba
commit
05975042a2
@ -5,10 +5,16 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Capture and store everything sent through io.printf() during the
|
||||||
|
-- execution of the supplied function.
|
||||||
--
|
--
|
||||||
-- Prepare to capture the output from all subsequent calls to io.printf(),
|
-- @param fn
|
||||||
-- used for automated testing of the generators.
|
-- The function to execute. All calls to io.printf() will be
|
||||||
--
|
-- caught and stored.
|
||||||
|
-- @return
|
||||||
|
-- The captured output.
|
||||||
|
---
|
||||||
|
|
||||||
function io.capture(fn)
|
function io.capture(fn)
|
||||||
-- start a new capture without forgetting the old one
|
-- start a new capture without forgetting the old one
|
||||||
@ -48,19 +54,18 @@
|
|||||||
-- subdirectories in the filename if "mode" is set to writeable.
|
-- subdirectories in the filename if "mode" is set to writeable.
|
||||||
--
|
--
|
||||||
|
|
||||||
local builtin_open = io.open
|
premake.override(io, "open", function(base, fname, mode)
|
||||||
function io.open(fname, mode)
|
if mode then
|
||||||
if (mode) then
|
if mode:find("w") then
|
||||||
if (mode:find("w")) then
|
|
||||||
local dir = path.getdirectory(fname)
|
local dir = path.getdirectory(fname)
|
||||||
ok, err = os.mkdir(dir)
|
ok, err = os.mkdir(dir)
|
||||||
if (not ok) then
|
if not ok then
|
||||||
error(err, 0)
|
error(err, 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return builtin_open(fname, mode)
|
return base(fname, mode)
|
||||||
end
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -69,11 +74,11 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
function io.printf(msg, ...)
|
function io.printf(msg, ...)
|
||||||
|
local s
|
||||||
if type(msg) == "number" then
|
if type(msg) == "number" then
|
||||||
local str, fmt, x = unpack(arg)
|
s = string.rep(io.indent or "\t", msg) .. string.format(...)
|
||||||
s = string.rep(io.indent or "\t", msg) .. string.format(unpack(arg))
|
|
||||||
else
|
else
|
||||||
s = string.format(msg, unpack(arg))
|
s = string.format(msg, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not io._captured then
|
if not io._captured then
|
||||||
@ -100,7 +105,7 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
function _p(msg, ...)
|
function _p(msg, ...)
|
||||||
io.printf(msg, unpack(arg))
|
io.printf(msg, ...)
|
||||||
if not io._captured then
|
if not io._captured then
|
||||||
io.write(io.eol or "\n")
|
io.write(io.eol or "\n")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user