From e74ad783a0c2b9b774f79e2908b960236cd02ee0 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Tue, 2 Sep 2014 19:01:20 +0100 Subject: [PATCH] Set metatable to _preconnect when disconnected and add connected field --- doc/irc.luadoc | 1 + init.lua | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/irc.luadoc b/doc/irc.luadoc index 4025910..c33a0b1 100644 --- a/doc/irc.luadoc +++ b/doc/irc.luadoc @@ -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. diff --git a/init.lua b/init.lua index a407ca8..194b692 100644 --- a/init.lua +++ b/init.lua @@ -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)