Add __tostring metamethods to prototypes
This is nice to have, and aids with debugging and interactive usage.
This commit is contained in:
@@ -27,6 +27,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local API = {}
|
local API = {}
|
||||||
|
API.__name = "matrix.api"
|
||||||
API.__index = API
|
API.__index = API
|
||||||
|
|
||||||
setmetatable(API, { __call = function (self, base_url, token, http_factory)
|
setmetatable(API, { __call = function (self, base_url, token, http_factory)
|
||||||
@@ -40,6 +41,10 @@ setmetatable(API, { __call = function (self, base_url, token, http_factory)
|
|||||||
}, API)
|
}, API)
|
||||||
end })
|
end })
|
||||||
|
|
||||||
|
function API:__tostring()
|
||||||
|
return self.__name .. "{" .. self.base_url .. "}"
|
||||||
|
end
|
||||||
|
|
||||||
function API:_quote(string)
|
function API:_quote(string)
|
||||||
return self._http:quote(string)
|
return self._http:quote(string)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,12 +7,17 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
local User = {}
|
local User = {}
|
||||||
|
User.__name = "matrix.user"
|
||||||
User.__index = User
|
User.__index = User
|
||||||
|
|
||||||
setmetatable(User, { __call = function (self, client, user_id)
|
setmetatable(User, { __call = function (self, client, user_id)
|
||||||
return setmetatable({ user_id = user_id, _client = client }, User)
|
return setmetatable({ user_id = user_id, _client = client }, User)
|
||||||
end })
|
end })
|
||||||
|
|
||||||
|
function User:__tostring()
|
||||||
|
return self.__name .. "{" .. self.user_id .. "}"
|
||||||
|
end
|
||||||
|
|
||||||
function User:get_display_name()
|
function User:get_display_name()
|
||||||
return self._client._api:get_display_name(self.user_id)
|
return self._client._api:get_display_name(self.user_id)
|
||||||
end
|
end
|
||||||
@@ -32,6 +37,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local Room = {}
|
local Room = {}
|
||||||
|
Room.__name = "matrix.room"
|
||||||
Room.__index = Room
|
Room.__index = Room
|
||||||
|
|
||||||
setmetatable(Room, { __call = function (self, client, room_id)
|
setmetatable(Room, { __call = function (self, client, room_id)
|
||||||
@@ -43,6 +49,10 @@ setmetatable(Room, { __call = function (self, client, room_id)
|
|||||||
}, Room)
|
}, Room)
|
||||||
end })
|
end })
|
||||||
|
|
||||||
|
function Room:__tostring()
|
||||||
|
return self.__name .. "{" .. self.room_id .. "}"
|
||||||
|
end
|
||||||
|
|
||||||
function Room:send_text(text)
|
function Room:send_text(text)
|
||||||
return self._client._api:send_message(self.room_id, text)
|
return self._client._api:send_message(self.room_id, text)
|
||||||
end
|
end
|
||||||
@@ -81,6 +91,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local Client = {}
|
local Client = {}
|
||||||
|
Client.__name = "matrix.client"
|
||||||
Client.__index = Client
|
Client.__index = Client
|
||||||
|
|
||||||
setmetatable(Client, { __call = function (self, base_url, token, http_factory)
|
setmetatable(Client, { __call = function (self, base_url, token, http_factory)
|
||||||
@@ -95,6 +106,10 @@ setmetatable(Client, { __call = function (self, base_url, token, http_factory)
|
|||||||
return c
|
return c
|
||||||
end })
|
end })
|
||||||
|
|
||||||
|
function Client:__tostring()
|
||||||
|
return self.__name .. "{" .. self._api.base_url .. "}"
|
||||||
|
end
|
||||||
|
|
||||||
function Client:register_with_password(username, password, limit)
|
function Client:register_with_password(username, password, limit)
|
||||||
return self:_logged_in(self._api:register("m.login.password",
|
return self:_logged_in(self._api:register("m.login.password",
|
||||||
{ user = username, password = password }), limit)
|
{ user = username, password = password }), limit)
|
||||||
|
|||||||
@@ -18,8 +18,13 @@ local CqHttpClient = {
|
|||||||
quote = function (self, text) return encodeURI(text) end,
|
quote = function (self, text) return encodeURI(text) end,
|
||||||
unquote = function (self, text) return decodeURI(text) end,
|
unquote = function (self, text) return decodeURI(text) end,
|
||||||
}
|
}
|
||||||
|
CqHttpClient.__name = "matrix.factory.chttp"
|
||||||
CqHttpClient.__index = CqHttpClient
|
CqHttpClient.__index = CqHttpClient
|
||||||
|
|
||||||
|
function CqHttpClient:__tostring()
|
||||||
|
return self.__name
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function headers_to_dict(h)
|
local function headers_to_dict(h)
|
||||||
local headers = {}
|
local headers = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user