From 324ed86335de9f0e0a81b61b104f6e2df2832f9d Mon Sep 17 00:00:00 2001 From: 20kdc Date: Sat, 28 Jul 2018 17:20:43 +0100 Subject: [PATCH] Update KMT to v1: be faster at reading --- claw/repo-claw.lua | 2 +- repository/apps/app-kmt.lua | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/claw/repo-claw.lua b/claw/repo-claw.lua index 752f539..24aeef8 100644 --- a/claw/repo-claw.lua +++ b/claw/repo-claw.lua @@ -91,7 +91,7 @@ return { }, ["app-kmt"] = { desc = "Line-terminal for MUDs & such", - v = 0, + v = 1, deps = { "neo", "zzz-license-pd" diff --git a/repository/apps/app-kmt.lua b/repository/apps/app-kmt.lua index 0f728a2..b36f378 100644 --- a/repository/apps/app-kmt.lua +++ b/repository/apps/app-kmt.lua @@ -113,7 +113,7 @@ while true do local e = {coroutine.yield()} if e[1] == "k.timer" then while true do - local b, e = tcp.read(1) + local b, e = tcp.read(neo.readBufSize) if not b then if e then incoming(":Warning: " .. e) @@ -123,12 +123,16 @@ while true do break elseif b == "" then break - elseif b ~= "\r" then - if b == "\n" then - incoming("<" .. tcpBuf) - tcpBuf = "" - else - tcpBuf = tcpBuf .. b + else + tcpBuf = tcpBuf .. b:gsub("\r", "") + while true do + local nlp = tcpBuf:find("\n") + if nlp then + incoming("<" .. tcpBuf:sub(1, nlp - 1)) + tcpBuf = tcpBuf:sub(nlp + 1) + else + break + end end end end