Set metatable to _preconnect when disconnected and add connected field

This commit is contained in:
ShadowNinja 2014-09-02 19:01:20 +01:00
parent e216ce4b23
commit e74ad783a0
2 changed files with 6 additions and 2 deletions

View File

@ -130,6 +130,7 @@ function irc:shutdown()
-- @name Connection
-- @class table
-- @field authed Boolean indicating whether the connection has completed registration.
-- @field connected Whether the connection is currently connected.
-- @field motd The server's message of the day. Can be nil.
-- @field nick The current nickname.
-- @field realname The real name sent to the server.

View File

@ -16,12 +16,15 @@ local meta_preconnect = {}
function meta_preconnect.__index(o, k)
local v = rawget(meta_preconnect, k)
if not v and meta[k] then
if v == nil and meta[k] ~= nil then
error(("field '%s' is not accessible before connecting"):format(k), 2)
end
return v
end
meta.connected = true
meta_preconnect.connected = false
function new(data)
local o = {
nick = assert(data.nick, "Field 'nick' is required");
@ -148,7 +151,7 @@ end
function meta:shutdown()
self.socket:close()
setmetatable(self, nil)
setmetatable(self, meta_preconnect)
end
local function getline(self, errlevel)