# HG changeset patch # User Kim Alvefur # Date 1418054689 -3600 # Node ID 64f55bcab9f78fc2124616c342da137a30938929 # Parent 4713f9d453ec98873b6e39589ede94aadcf6f6bf mod_statistics/prosodytop.lua: Simplify and fix buffering and line separation (thanks Ge0rG) diff -r 4713f9d453ec -r 64f55bcab9f7 mod_statistics/prosodytop.lua --- a/mod_statistics/prosodytop.lua Mon Dec 08 14:27:10 2014 +0100 +++ b/mod_statistics/prosodytop.lua Mon Dec 08 17:04:49 2014 +0100 @@ -86,26 +86,16 @@ --stdscr:mvaddstr(6, 0, "CONNECTED"); end - local partial; + local partial = ""; function stats_listener.onincoming(conn, data) --print("DATA", data) - if partial then - partial, data = nil, partial..data; - end - if not data:match("\n") then - partial = data; - return; - end + data = partial..data; local lastpos = 1; for line, pos in data:gmatch("([^\n]+)\n()") do lastpos = pos; handle_line(line); end - if lastpos == #data then - partial = nil; - else - partial = data:sub(lastpos); - end + partial = data:sub(lastpos); end function stats_listener.ondisconnect(conn, err)