diff options
| author | OpportunityLiu <[email protected]> | 2019-07-13 16:38:45 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-13 16:38:45 +0800 |
| commit | 78de198d8b1dc94fce77680b219f9f512849992d (patch) | |
| tree | 6c5308e4bf3988e2c4188dd1b4afa6430faa589e | |
| parent | c1d09f317b73520624a7a6ed0ab63f2dd26ba181 (diff) | |
fix file.line
| -rw-r--r-- | xmake/core/base/io.lua | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua index 114a7a00c..e14cd32e9 100644 --- a/xmake/core/base/io.lua +++ b/xmake/core/base/io.lua @@ -37,16 +37,18 @@ function _file:read(fmt, opt) return self:_read(fmt, opt.continuation) end +-- iterator of lines +function _file._lines_iter(data) + local l = data.file:read("l", data.opt) + if not l and data.opt.close_on_finished then + data.file:close() + end + return l +end + -- read all lines from a file function _file:lines(opt) - opt = opt or {} - return function() - local l = self:read("l", opt) - if not l and opt.close_on_finished then - self:close() - end - return l - end + return _file._lines_iter, { file = assert(self), opt = opt or {} } end -- print file @@ -223,7 +225,7 @@ function io.save(filepath, object, opt) -- ok return true end - + -- load object from the given file function io.load(filepath, opt) |
