summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-03-27 17:57:41 +0800
committerruki <[email protected]>2017-03-27 17:58:56 +0800
commit71d627e4aa9b5780e63fc6b679c74548844c5feb (patch)
tree46d8e8c874d045ca1f4d492b6edf82f5d716ae54
parent235bb967883ab0686bab731c8e94a4a0bb7677ab (diff)
fix io.read and io.write raw lua api
-rw-r--r--docs/manual.md14
-rwxr-xr-xdocs/zh/manual.md14
-rw-r--r--xmake/actions/install/main.lua3
-rw-r--r--xmake/actions/uninstall/main.lua3
-rw-r--r--xmake/core/base/io.lua8
-rw-r--r--xmake/core/base/os.lua6
-rw-r--r--xmake/core/sandbox/modules/io.lua11
-rw-r--r--xmake/languages/c++/check_main.lua2
-rw-r--r--xmake/languages/dlang/check_main.lua2
-rw-r--r--xmake/languages/golang/check_main.lua2
-rw-r--r--xmake/languages/objc++/check_main.lua2
-rw-r--r--xmake/languages/rust/check_main.lua2
-rw-r--r--xmake/platforms/iphoneos/check.lua2
-rw-r--r--xmake/platforms/watchos/check.lua2
-rw-r--r--xmake/tools/ar.lua2
-rw-r--r--xmake/tools/cl.lua2
-rw-r--r--xmake/tools/dmd.lua2
-rw-r--r--xmake/tools/gcc.lua4
-rw-r--r--xmake/tools/gccgo.lua2
-rw-r--r--xmake/tools/go.lua2
-rw-r--r--xmake/tools/lib.lua2
-rw-r--r--xmake/tools/link.lua4
-rw-r--r--xmake/tools/ml.lua2
-rw-r--r--xmake/tools/rustc.lua2
24 files changed, 48 insertions, 49 deletions
diff --git a/docs/manual.md b/docs/manual.md
index e0e0d9390..0a011b70f 100644
--- a/docs/manual.md
+++ b/docs/manual.md
@@ -3820,8 +3820,8 @@ io操作模块,扩展了lua内置的io模块,提供更多易用的接口。
| [io.open](#io-open) | 打开文件用于读写 | >= 2.0.1 |
| [io.load](#io-load) | 从指定路径文件反序列化加载所有table内容 | >= 2.0.1 |
| [io.save](#io-save) | 序列化保存所有table内容到指定路径文件 | >= 2.0.1 |
-| [io.read](#io-read) | 从指定路径文件读取所有内容 | >= 2.0.1 |
-| [io.write](#io-write) | 写入所有内容到指定路径文件 | >= 2.0.1 |
+| [io.readfile](#io.readfile) | 从指定路径文件读取所有内容 | >= 2.1.3 |
+| [io.writefile](#io.writefile) | 写入所有内容到指定路径文件 | >= 2.1.3 |
| [io.gsub](#io-gsub) | 全文替换指定路径文件的内容 | >= 2.0.1 |
| [io.tail](#io-tail) | 读取和显示文件的尾部内容 | >= 2.0.1 |
| [io.cat](#io-cat) | 读取和显示文件的所有内容 | >= 2.0.1 |
@@ -3844,7 +3844,7 @@ if file then
end
```
-或者可以使用[io.read](#io-read)更加快速地读取。
+或者可以使用[io.readfile](#io.readfile)更加快速地读取。
如果要写文件,可以这么操作:
@@ -3906,24 +3906,24 @@ io.save("xxx.txt", {a = "a", b = "b", c = "c"})
}
```
-###### io.read
+###### io.readfile
- 从指定路径文件读取所有内容
可在不打开文件的情况下,直接读取整个文件的内容,更加的方便,例如:
```lua
-local data = io.read("xxx.txt")
+local data = io.readfile("xxx.txt")
```
-###### io.write
+###### io.writefile
- 写入所有内容到指定路径文件
可在不打开文件的情况下,直接写入整个文件的内容,更加的方便,例如:
```lua
-io.write("xxx.txt", "all data")
+io.writefile("xxx.txt", "all data")
```
###### io.gsub
diff --git a/docs/zh/manual.md b/docs/zh/manual.md
index 1d63edec7..1174d8899 100755
--- a/docs/zh/manual.md
+++ b/docs/zh/manual.md
@@ -3822,8 +3822,8 @@ io操作模块,扩展了lua内置的io模块,提供更多易用的接口。
| [io.open](#io-open) | 打开文件用于读写 | >= 2.0.1 |
| [io.load](#io-load) | 从指定路径文件反序列化加载所有table内容 | >= 2.0.1 |
| [io.save](#io-save) | 序列化保存所有table内容到指定路径文件 | >= 2.0.1 |
-| [io.read](#io-read) | 从指定路径文件读取所有内容 | >= 2.0.1 |
-| [io.write](#io-write) | 写入所有内容到指定路径文件 | >= 2.0.1 |
+| [io.readfile](#io.readfile) | 从指定路径文件读取所有内容 | >= 2.1.3 |
+| [io.writefile](#io.writefile) | 写入所有内容到指定路径文件 | >= 2.1.3 |
| [io.gsub](#io-gsub) | 全文替换指定路径文件的内容 | >= 2.0.1 |
| [io.tail](#io-tail) | 读取和显示文件的尾部内容 | >= 2.0.1 |
| [io.cat](#io-cat) | 读取和显示文件的所有内容 | >= 2.0.1 |
@@ -3846,7 +3846,7 @@ if file then
end
```
-或者可以使用[io.read](#io-read)更加快速地读取。
+或者可以使用[io.readfile](#io.readfile)更加快速地读取。
如果要写文件,可以这么操作:
@@ -3908,24 +3908,24 @@ io.save("xxx.txt", {a = "a", b = "b", c = "c"})
}
```
-###### io.read
+###### io.readfile
- 从指定路径文件读取所有内容
可在不打开文件的情况下,直接读取整个文件的内容,更加的方便,例如:
```lua
-local data = io.read("xxx.txt")
+local data = io.readfile("xxx.txt")
```
-###### io.write
+###### io.writefile
- 写入所有内容到指定路径文件
可在不打开文件的情况下,直接写入整个文件的内容,更加的方便,例如:
```lua
-io.write("xxx.txt", "all data")
+io.writefile("xxx.txt", "all data")
```
###### io.gsub
diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua
index be09c75ff..97ca5ac99 100644
--- a/xmake/actions/install/main.lua
+++ b/xmake/actions/install/main.lua
@@ -73,10 +73,9 @@ function main()
cprint("${bright yellow}note: ${default yellow}try continue to install with administrator permission again?")
cprint("please input: y (y/n)")
- -- TODO fix read api
-- get answer
io.flush()
- if io._read() == 'y' then
+ if io.read() == 'y' then
-- install target with administrator permission
os.runv(os.sudo(), argv)
diff --git a/xmake/actions/uninstall/main.lua b/xmake/actions/uninstall/main.lua
index 297c56bc6..36342f7b6 100644
--- a/xmake/actions/uninstall/main.lua
+++ b/xmake/actions/uninstall/main.lua
@@ -73,10 +73,9 @@ function main()
cprint("${bright yellow}note: ${default yellow}try continue to uninstall with administrator permission again?")
cprint("please input: y (y/n)")
- -- TODO fix read api
-- get answer
io.flush()
- if io._read() == 'y' then
+ if io.read() == 'y' then
-- install target with administrator permission
os.runv(os.sudo(), argv)
diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua
index adc70811c..2d59051c7 100644
--- a/xmake/core/base/io.lua
+++ b/xmake/core/base/io.lua
@@ -200,7 +200,7 @@ function _file:load()
end
-- read all data from file
-function io.readall(filepath)
+function io.readfile(filepath)
-- open file
local file = io.open(filepath, "r")
@@ -220,7 +220,7 @@ function io.readall(filepath)
end
-- write data to file
-function io.writall(filepath, data)
+function io.writefile(filepath, data)
-- open file
local file = io.open(filepath, "w")
@@ -333,7 +333,7 @@ end
function io.gsub(filepath, pattern, replace)
-- read all data from file
- local data, errors = io.readall(filepath)
+ local data, errors = io.readfile(filepath)
if not data then return nil, 0, errors end
-- replace it
@@ -347,7 +347,7 @@ function io.gsub(filepath, pattern, replace)
-- replace ok?
if count ~= 0 then
-- write all data to file
- local ok, errors = io.writall(filepath, data)
+ local ok, errors = io.writefile(filepath, data)
if not ok then return nil, 0, errors end
end
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 39be26ade..542751d54 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -443,7 +443,7 @@ function os.runv(shellname, argv)
if ok ~= 0 then
-- make errors
- local errors = io.readall(log)
+ local errors = io.readfile(log)
if not errors or #errors == 0 then
if argv ~= nil then
errors = string.format("runv(%s %s) failed(%d)!", shellname, table.concat(argv, ' '), ok)
@@ -547,8 +547,8 @@ function os.iorunv(shellname, argv)
local ok = os.execv(shellname, argv, outfile, errfile)
-- get output and error data
- local outdata = io.readall(outfile)
- local errdata = io.readall(errfile)
+ local outdata = io.readfile(outfile)
+ local errdata = io.readfile(errfile)
-- remove the temporary output and error file
os.rm(outfile)
diff --git a/xmake/core/sandbox/modules/io.lua b/xmake/core/sandbox/modules/io.lua
index d8b110c6e..bc01f696c 100644
--- a/xmake/core/sandbox/modules/io.lua
+++ b/xmake/core/sandbox/modules/io.lua
@@ -34,7 +34,8 @@ local sandbox_io = sandbox_io or {}
-- inherit some builtin interfaces
sandbox_io.flush = io.flush
-sandbox_io._read = io.read
+sandbox_io.read = io.read
+sandbox_io.write = io.write
-- print file
function sandbox_io._print(self, ...)
@@ -137,7 +138,7 @@ function sandbox_io.save(filepath, object)
end
-- read all data from file
-function sandbox_io.read(filepath)
+function sandbox_io.readfile(filepath)
-- check
assert(filepath)
@@ -146,7 +147,7 @@ function sandbox_io.read(filepath)
filepath = vformat(filepath)
-- done
- local result, errors = io.readall(filepath)
+ local result, errors = io.readfile(filepath)
if not result then
raise(errors)
end
@@ -156,7 +157,7 @@ function sandbox_io.read(filepath)
end
-- write all data to file
-function sandbox_io.write(filepath, data)
+function sandbox_io.writefile(filepath, data)
-- check
assert(filepath)
@@ -165,7 +166,7 @@ function sandbox_io.write(filepath, data)
filepath = vformat(filepath)
-- done
- local ok, errors = io.writall(filepath, data)
+ local ok, errors = io.writefile(filepath, data)
if not ok then
raise(errors)
end
diff --git a/xmake/languages/c++/check_main.lua b/xmake/languages/c++/check_main.lua
index f0c12b582..d5d434d8f 100644
--- a/xmake/languages/c++/check_main.lua
+++ b/xmake/languages/c++/check_main.lua
@@ -27,7 +27,7 @@
function main(sourcefile)
-- load source code
- local sourcecode = io.read(sourcefile)
+ local sourcecode = io.readfile(sourcefile)
-- remove comment first
sourcecode = sourcecode:gsub("/%*.-%*/", "")
diff --git a/xmake/languages/dlang/check_main.lua b/xmake/languages/dlang/check_main.lua
index f69c4b142..9eb1d43bb 100644
--- a/xmake/languages/dlang/check_main.lua
+++ b/xmake/languages/dlang/check_main.lua
@@ -26,7 +26,7 @@
function main(sourcefile)
-- load source code
- local sourcecode = io.read(sourcefile)
+ local sourcecode = io.readfile(sourcefile)
-- remove comment first
sourcecode = sourcecode:gsub("/%*.-%*/", "")
diff --git a/xmake/languages/golang/check_main.lua b/xmake/languages/golang/check_main.lua
index 8c7d2931e..62471650b 100644
--- a/xmake/languages/golang/check_main.lua
+++ b/xmake/languages/golang/check_main.lua
@@ -26,7 +26,7 @@
function main(sourcefile)
-- load source code
- local sourcecode = io.read(sourcefile)
+ local sourcecode = io.readfile(sourcefile)
-- remove comment first
sourcecode = sourcecode:gsub("/%*.-%*/", "")
diff --git a/xmake/languages/objc++/check_main.lua b/xmake/languages/objc++/check_main.lua
index f0c12b582..d5d434d8f 100644
--- a/xmake/languages/objc++/check_main.lua
+++ b/xmake/languages/objc++/check_main.lua
@@ -27,7 +27,7 @@
function main(sourcefile)
-- load source code
- local sourcecode = io.read(sourcefile)
+ local sourcecode = io.readfile(sourcefile)
-- remove comment first
sourcecode = sourcecode:gsub("/%*.-%*/", "")
diff --git a/xmake/languages/rust/check_main.lua b/xmake/languages/rust/check_main.lua
index a02da9d6f..75cd89356 100644
--- a/xmake/languages/rust/check_main.lua
+++ b/xmake/languages/rust/check_main.lua
@@ -26,7 +26,7 @@
function main(sourcefile)
-- load source code
- local sourcecode = io.read(sourcefile)
+ local sourcecode = io.readfile(sourcefile)
-- remove comment first
sourcecode = sourcecode:gsub("/%*.-%*/", "")
diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua
index 3292199d4..d247c4bf8 100644
--- a/xmake/platforms/iphoneos/check.lua
+++ b/xmake/platforms/iphoneos/check.lua
@@ -31,7 +31,7 @@ function _check_as(shellname)
-- make an empty tmp.S
local tmpfile = path.join(os.tmpdir(), "xmake.checker.as.S")
- io.write(tmpfile, "")
+ io.writefile(tmpfile, "")
-- check it
os.run("%s -arch armv7 -o %s -c %s", shellname, os.nuldev(), tmpfile)
diff --git a/xmake/platforms/watchos/check.lua b/xmake/platforms/watchos/check.lua
index f22ec4dd5..2475495bf 100644
--- a/xmake/platforms/watchos/check.lua
+++ b/xmake/platforms/watchos/check.lua
@@ -31,7 +31,7 @@ function _check_as(shellname)
-- make an empty tmp.S
local tmpfile = path.join(os.tmpdir(), "xmake.checker.as.S")
- io.write(tmpfile, "")
+ io.writefile(tmpfile, "")
-- check it
os.run("%s -arch armv7 -o %s -c %s", shellname, os.nuldev(), tmpfile)
diff --git a/xmake/tools/ar.lua b/xmake/tools/ar.lua
index 4c82a7c5b..281055c40 100644
--- a/xmake/tools/ar.lua
+++ b/xmake/tools/ar.lua
@@ -119,7 +119,7 @@ function check(flags)
local libraryfile = path.join(os.tmpdir(), "xmake.ar.a")
local objectfile = path.join(os.tmpdir(), "xmake.ar.o")
local sourcefile = path.join(os.tmpdir(), "xmake.ar.c")
- io.write(sourcefile, "int test(void)\n{return 0;}")
+ io.writefile(sourcefile, "int test(void)\n{return 0;}")
-- make flags
local arflags = table.concat(_g.arflags, " ")
diff --git a/xmake/tools/cl.lua b/xmake/tools/cl.lua
index f67f072ab..68881995e 100644
--- a/xmake/tools/cl.lua
+++ b/xmake/tools/cl.lua
@@ -322,7 +322,7 @@ function check(flags)
-- make an stub source file
local objectfile = os.tmpfile() .. ".obj"
local sourcefile = os.tmpfile() .. ".c"
- io.write(sourcefile, "int main(int argc, char** argv)\n{return 0;}")
+ io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}")
-- check it
os.run("%s -c %s -Fo%s %s", _g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile)
diff --git a/xmake/tools/dmd.lua b/xmake/tools/dmd.lua
index 844c94e92..10fb28342 100644
--- a/xmake/tools/dmd.lua
+++ b/xmake/tools/dmd.lua
@@ -201,7 +201,7 @@ function check(flags)
local sourcefile = os.tmpfile() .. ".d"
-- make stub code
- io.write(sourcefile, "void main() {\n}")
+ io.writefile(sourcefile, "void main() {\n}")
-- check it
os.run("%s -c %s -of%s %s", _g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile)
diff --git a/xmake/tools/gcc.lua b/xmake/tools/gcc.lua
index a3f40b4b0..d4dc2d930 100644
--- a/xmake/tools/gcc.lua
+++ b/xmake/tools/gcc.lua
@@ -340,7 +340,7 @@ function _compile1(sourcefile, objectfile, incdepfile, flags)
-- translate it
local results = {}
- local incdeps = io.read(tmpfile)
+ local incdeps = io.readfile(tmpfile)
for includefile in string.gmatch(incdeps, "%s+([%w/%.%-%+_%$%.]+)") do
-- save it if belong to the project
@@ -385,7 +385,7 @@ function check(flags)
local sourcefile = os.tmpfile() .. ".c" .. ifelse(_g.kind == "cxx", "pp", "")
-- make stub code
- io.write(sourcefile, "int main(int argc, char** argv)\n{return 0;}")
+ io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}")
-- check it
os.run("%s -c %s -o %s %s", _g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile)
diff --git a/xmake/tools/gccgo.lua b/xmake/tools/gccgo.lua
index 48bb5ee19..1254130d4 100644
--- a/xmake/tools/gccgo.lua
+++ b/xmake/tools/gccgo.lua
@@ -40,7 +40,7 @@ function check(flags)
local sourcefile = os.tmpfile() .. ".go"
-- make stub code
- io.write(sourcefile, "package main\nfunc main() {\n}")
+ io.writefile(sourcefile, "package main\nfunc main() {\n}")
-- check it
os.run("%s -c %s -o %s %s", _super._g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile)
diff --git a/xmake/tools/go.lua b/xmake/tools/go.lua
index 0d9bd00f4..3e7afe80d 100644
--- a/xmake/tools/go.lua
+++ b/xmake/tools/go.lua
@@ -164,7 +164,7 @@ function check(flags)
local sourcefile = os.tmpfile() .. ".go"
-- make stub code
- io.write(sourcefile, "package main\nfunc main() {\n}")
+ io.writefile(sourcefile, "package main\nfunc main() {\n}")
-- check it
os.run("%s tool compile %s -o %s %s", _g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile)
diff --git a/xmake/tools/lib.lua b/xmake/tools/lib.lua
index 62787b405..7b0a851e8 100644
--- a/xmake/tools/lib.lua
+++ b/xmake/tools/lib.lua
@@ -80,7 +80,7 @@ function check(flags)
local libfile = os.tmpfile() .. ".lib"
local objfile = os.tmpfile() .. ".obj"
local srcfile = os.tmpfile() .. ".c"
- io.write(srcfile, "int test(void)\n{return 0;}")
+ io.writefile(srcfile, "int test(void)\n{return 0;}")
-- check it
os.run("cl -c -Fo%s %s", objfile, srcfile)
diff --git a/xmake/tools/link.lua b/xmake/tools/link.lua
index 7d4ae9f56..aa99377fb 100644
--- a/xmake/tools/link.lua
+++ b/xmake/tools/link.lua
@@ -147,9 +147,9 @@ function check(flags)
-- main entry
if flags and flags:lower():find("subsystem:windows") then
- io.write(sourcefile, "int WinMain(void* instance, void* previnst, char** argv, int argc)\n{return 0;}")
+ io.writefile(sourcefile, "int WinMain(void* instance, void* previnst, char** argv, int argc)\n{return 0;}")
else
- io.write(sourcefile, "int main(int argc, char** argv)\n{return 0;}")
+ io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}")
end
-- check it
diff --git a/xmake/tools/ml.lua b/xmake/tools/ml.lua
index 874d0be78..d8ddaee29 100644
--- a/xmake/tools/ml.lua
+++ b/xmake/tools/ml.lua
@@ -152,7 +152,7 @@ function check(flags)
-- make an stub source file
local objectfile = os.tmpfile() .. ".obj"
local sourcefile = os.tmpfile() .. ".asm"
- io.write(sourcefile, "end")
+ io.writefile(sourcefile, "end")
-- check it
os.run("%s -c %s -Fo%s %s", _g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile)
diff --git a/xmake/tools/rustc.lua b/xmake/tools/rustc.lua
index 6456e7a3a..5727544d2 100644
--- a/xmake/tools/rustc.lua
+++ b/xmake/tools/rustc.lua
@@ -148,7 +148,7 @@ function check(flags)
local sourcefile = os.tmpfile() .. ".rs"
-- make stub code
- io.write(sourcefile, "fn main() {\n}")
+ io.writefile(sourcefile, "fn main() {\n}")
-- check it
os.run("%s --emit obj %s -o %s %s", _g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile)