blob: f5ee64810ea5e2d46db76fae874ec2aeb038b8bf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
--
-- io.lua
-- Additions to the I/O namespace.
-- Copyright (c) 2008-2009 Jason Perkins and the Premake project
--
--
-- Prepare to capture the output from all subsequent calls to io.printf(),
-- used for automated testing of the generators.
--
function io.capture()
io.captured = ''
end
--
-- Returns the captured text and stops capturing.
--
function io.endcapture()
local captured = io.captured
io.captured = nil
return captured
end
--
-- Open an overload of the io.open() function, which will create any missing
-- subdirectories in the filename if "mode" is set to writeable.
--
local builtin_open = io.open
function io.open(fname, mode)
if (mode) then
if (mode:find("w")) then
local dir = path.getdirectory(fname)
ok, err = os.mkdir(dir)
if (not ok) then
error(err, 0)
end
end
end
return builtin_open(fname, mode)
end
--
-- A shortcut for printing formatted output to an output stream.
--
function io.printf(msg, ...)
local arg={...}
if not io.eol then
io.eol = "\n"
end
if not io.indent then
io.indent = "\t"
end
if type(msg) == "number" then
s = string.rep(io.indent, msg) .. string.format(table.unpack(arg))
else
s = string.format(msg, table.unpack(arg))
end
if io.captured then
io.captured = io.captured .. s .. io.eol
else
io.write(s)
io.write(io.eol)
end
end
--
-- Because I use io.printf() so often in the generators, create a terse shortcut
-- for it. This saves me typing, and also reduces the size of the executable.
--
_p = io.printf
|