forked from premake/premake-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.lua
More file actions
47 lines (41 loc) · 934 Bytes
/
io.lua
File metadata and controls
47 lines (41 loc) · 934 Bytes
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
--
-- io.lua
-- Additions to the I/O namespace.
-- Copyright (c) 2008-2014 Jason Perkins and the Premake project
--
--
-- Open an overload of the io.open() function, which will create any missing
-- subdirectories in the filename if "mode" is set to writeable.
--
premake.override(io, "open", function(base, fname, mode)
if mode and (mode:find("w") or mode:find("a")) then
local dir = path.getdirectory(fname)
ok, err = os.mkdir(dir)
if not ok then
error(err, 0)
end
end
return base(fname, mode)
end)
--
-- Write content to a new file.
--
function io.writefile(filename, content)
local file = io.open(filename, "w+b")
if file then
file:write(content)
file:close()
return true
end
end
--
-- Read content from new file.
--
function io.readfile(filename)
local file = io.open(filename, "rb")
if file then
local content = file:read("*a")
file:close()
return content
end
end