From 0890ddb40f59170f1c672f7ed10b89566fe97c93 Mon Sep 17 00:00:00 2001 From: equa Date: Thu, 10 Mar 2022 05:23:02 +0000 Subject: make luacheck happy --- bot.lua | 31 ++++++++++++++----------------- fs.lua | 11 +++++------ mom.lua | 3 +-- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/bot.lua b/bot.lua index 63d977f..92927aa 100644 --- a/bot.lua +++ b/bot.lua @@ -1,24 +1,12 @@ local cqueues = require("cqueues") local socket = require("cqueues.socket") -local condition = require("cqueues.condition") -local std = require("posix.unistd") -local stdio = require("posix.stdio") local fs = require("fs") local fifo = require("fifo") local mom = require("mom") -function irc_dump(fifo, socket) - for data in fifo:iter() do - data = emit_message(data) - if not string.match(data, "[\r\n]") and #string <= 510 then - socket:write(data .. "\r\n") - end - end -end - -function parse_message(data) +local function parse_message(data) if string.match(data, "[\0\r\n]") then return nil, "illegal character" end local pos = 1 @@ -47,7 +35,7 @@ function parse_message(data) return { params = params, command = command, prefix = prefix } end -function emit_message(message) +local function emit_message(message) local out = {} if message.prefix then table.insert(out, message.prefix) @@ -74,7 +62,7 @@ end local irc_handlers = {} -function source_to_nick(source) +local function source_to_nick(source) return string.match(source, "[^!@]*") end @@ -84,6 +72,15 @@ do -- test source_to_nick assert(source_to_nick("man@host") == "man") end +local function irc_dump(fifo, socket) + for data in fifo:iter() do + data = emit_message(data) + if not string.match(data, "[\r\n]") and #string <= 510 then + socket:write(data .. "\r\n") + end + end +end + function irc_handlers.PING(state, line) fifo.put(state.queue, { command = "PONG", params = line.params }) end @@ -137,7 +134,7 @@ function irc_handlers.PRIVMSG(state, line) ) end -function handle_ed_rx(state) +local function handle_ed_rx(state) for line in state.rx_queue:iter() do if line[2] == "line" then state.queue:put({ @@ -170,7 +167,7 @@ function handle_ed_rx(state) end end -function irc_connect(loop, host, config) +local function irc_connect(loop, host, config) local state = { -- IRC output queue (message objects) queue = fifo.new(), diff --git a/fs.lua b/fs.lua index 153e611..f612a59 100644 --- a/fs.lua +++ b/fs.lua @@ -4,7 +4,6 @@ -- throwing it, which may be what we want. code depends on this local unistd = require("posix.unistd") local cqueues = require("cqueues") -local dkjson = require("dkjson") local file = {} @@ -33,7 +32,7 @@ end -- buffers are arrays of objects containing "data" (a string) and "index" (their position) -- indexing allows us to avoid recreating string objects -function buffer_length(buf) +local function buffer_length(buf) local total = 0 for _, entry in ipairs(buf) do total = total + #entry.data - entry.index + 1 @@ -42,12 +41,12 @@ function buffer_length(buf) end -- returns nil on empty length -function buffer_get(buf, length) +local function buffer_get(buf, length) local out = {} if not length then length = buffer_length(buf) end while length > 0 do assert(#buf > 0) - + local x = string.sub(buf[1].data, buf[1].index, buf[1].index + length - 1) table.insert(out, x) if #buf[1].data - buf[1].index + 1 <= length then @@ -60,7 +59,7 @@ function buffer_get(buf, length) if out[1] then return table.concat(out) else return nil end end -function buffer_char_index(buf, char) +local function buffer_char_index(buf, char) local num = 1 for _, entry in ipairs(buf) do if string.find(entry.data, char, entry.index, true) then @@ -81,7 +80,7 @@ do assert(buffer_length(test_buf) == 1) end -function try_read(buffer, fd, max) +local function try_read(buffer, fd, max) cqueues.poll({ pollfd = fd, events = function () return "r" end }) local data, _, errno = unistd.read(fd, max) diff --git a/mom.lua b/mom.lua index 4d14bd9..ef0f4c8 100644 --- a/mom.lua +++ b/mom.lua @@ -4,7 +4,6 @@ -- SIGCHILD; since this is the only time we make subprocesses in the scope -- of this program, this is fine. -local cqueues = require("cqueues") local signal = require("cqueues.signal") local wait = require("posix.sys.wait") @@ -127,7 +126,7 @@ function mom.tend(m) local pid, status = wait.wait(-1, wait.WNOHANG | wait.WUNTRACED) if pid and status ~= "running" then - client_id = m.pids[pid] + local client_id = m.pids[pid] m.pids[pid] = nil -- TODO: only restart sometimes mom.start_process(m, client_id) -- cgit 1.3.0-6-gf8a5