This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ringbuf={} | |
ringbuf.eof=0 | |
ringbuf.size=0 | |
ringbuf.__index=ringbuf | |
function ringbuf:new(size) | |
size=tonumber(size) | |
if not size then | |
return nil, "arg must be an number" | |
elseif size<1 then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env lua | |
-- Example usage: ./tail.lua logfile -10 | |
local fd=io.open(arg[1],"r") | |
local lines_to_read=math.abs(tonumber(arg[2]) or 0) | |
local eof=fd:seek("end",-1) | |
local pos=eof | |
local lines_read=0 | |
local buf={} | |
local buf_len=0 | |
while pos do |