diff options
| author | ruki <[email protected]> | 2015-12-03 09:25:41 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-12-03 09:25:41 +0800 |
| commit | 8ac451453097e9637f02fb043f86eaf916929e65 (patch) | |
| tree | 5da21bdbfdd294866b3be5e780d2ae81e3db096a /xmake/scripts/base/io.lua | |
| parent | 65be932e7f4212e56fabf232d95498b3b783d945 (diff) | |
fix show long error info bug
Diffstat (limited to 'xmake/scripts/base/io.lua')
| -rw-r--r-- | xmake/scripts/base/io.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/xmake/scripts/base/io.lua b/xmake/scripts/base/io.lua index 9c0ece688..66b23911a 100644 --- a/xmake/scripts/base/io.lua +++ b/xmake/scripts/base/io.lua @@ -273,5 +273,52 @@ function io.cat(filepath, linecount) end end +-- tail the given file +function io.tail(filepath, linecount) + + -- open file + local file = io.open(filepath, "r") + if file then + + -- read lines + local lines = {} + for line in file:lines() do + table.insert(lines, line) + end + + -- tail lines + local tails = {} + if #lines ~= 0 then + local count = 1 + for index = #lines, 1, -1 do + + -- show line + table.insert(tails, lines[index]) + + -- end? + if linecount and count >= linecount then + break + end + + -- update the line count + count = count + 1 + end + end + + -- show tails + if #tails ~= 0 then + for index = #tails, 1, -1 do + + -- show tail + print(tails[index]) + + end + end + + -- exit file + file:close() + end +end + -- return module: io return io |
