mirror of
https://github.com/ShadowNinja/LuaIRC.git
synced 2025-01-08 17:10:28 +01:00
Set metatable to _preconnect when disconnected and add connected field
This commit is contained in:
parent
e216ce4b23
commit
e74ad783a0
@ -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.
|
||||
|
7
init.lua
7
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)
|
||||
|
Loading…
Reference in New Issue
Block a user