Interpret format codes passed to meta:send() literally if there are no format arguments

This commit is contained in:
ShadowNinja 2013-06-17 11:38:13 -04:00
parent 1d0480adba
commit ddb788883e
3 changed files with 10 additions and 6 deletions

View File

@ -1,12 +1,16 @@
local table = table
local assert = assert
local select = select
module "irc"
local meta = _META
function meta:send(fmt, ...)
local bytes, err = self.socket:send(fmt:format(...) .. "\r\n")
function meta:send(msg, ...)
if select("#", ...) > 0 then
msg = msg:format(...)
end
local bytes, err = self.socket:send(msg .. "\r\n")
if not bytes and err ~= "timeout" and err ~= "wantwrite" then
self:invoke("OnDisconnect", err, true)

View File

@ -71,9 +71,9 @@ function irc:whois(nick)
function irc:topic(channel)
--- Send a raw line of IRC to the server.
-- @param fmt Line to be sent, excluding newline characters.
-- @param ... Format parameters for <code>fmt</code>, with <code>string.format</code> semantics.
function irc:send(fmt, ...)
-- @param msg Line to be sent, excluding newline characters.
-- @param ... Format parameters for <code>msg</code>, with <code>string.format</code> semantics. [optional]
function irc:send(msg, ...)
--- Send a message to a channel or user.
-- @param target Nick or channel to send to.

View File

@ -26,7 +26,7 @@ function meta_preconnect.__index(o, k)
local v = rawget(meta_preconnect, k)
if not v and meta[k] then
error("field '"..k.."' is not accessible before connecting", 2)
error(("field '%s' is not accessible before connecting"):format(k), 2)
end
return v
end