summaryrefslogtreecommitdiff
path: root/xmake/core/base/io.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2019-10-31 21:04:32 +0800
committerruki <[email protected]>2019-10-31 00:27:17 +0800
commit7d47837062fba756f66e7bea313cb59f9a026477 (patch)
tree1faef02540808728046c67d23c874f6118a0c774 /xmake/core/base/io.lua
parent057e930e41972cc5ee1812d16792dc6f6945279d (diff)
impl bytes index and ipairs
Diffstat (limited to 'xmake/core/base/io.lua')
-rw-r--r--xmake/core/base/io.lua20
1 files changed, 9 insertions, 11 deletions
diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua
index 6cc340242..6dc13ca30 100644
--- a/xmake/core/base/io.lua
+++ b/xmake/core/base/io.lua
@@ -219,18 +219,16 @@ function _file:_ensure_opened()
return true
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
+-- read all lines from file
function _file:lines(opt)
- return _file._lines_iter, { file = assert(self), opt = opt or {} }
+ 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
end
-- print file