mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Give HTTPResponse a to_string
This commit is contained in:
parent
072003c0fe
commit
90bcdc8bf5
|
@ -17,7 +17,8 @@ void HTTPResponse::createUserType(sol::table &c2)
|
|||
c2.new_usertype<HTTPResponse>( //
|
||||
"HTTPResponse", sol::no_constructor,
|
||||
// metamethods
|
||||
// TODO: add a __tostring
|
||||
sol::meta_method::to_string, &HTTPResponse::to_string, //
|
||||
|
||||
"data", &HTTPResponse::data, //
|
||||
"status", &HTTPResponse::status, //
|
||||
"error", &HTTPResponse::error //
|
||||
|
@ -49,5 +50,14 @@ QString HTTPResponse::error()
|
|||
return this->result_.formatError();
|
||||
}
|
||||
|
||||
QString HTTPResponse::to_string()
|
||||
{
|
||||
if (this->status().has_value())
|
||||
{
|
||||
return QStringView(u"<c2.HTTPResponse status %1>").arg(*this->status());
|
||||
}
|
||||
return "<c2.HTTPResponse no status>";
|
||||
}
|
||||
|
||||
} // namespace chatterino::lua::api
|
||||
#endif
|
||||
|
|
|
@ -11,6 +11,7 @@ class PluginController;
|
|||
} // namespace chatterino
|
||||
|
||||
namespace chatterino::lua::api {
|
||||
// NOLINTBEGIN(readability-identifier-naming)
|
||||
|
||||
/**
|
||||
* @lua@class HTTPResponse
|
||||
|
@ -52,7 +53,14 @@ public:
|
|||
* @exposed HTTPResponse:error
|
||||
*/
|
||||
QString error();
|
||||
|
||||
/**
|
||||
* @lua@return string
|
||||
* @exposed HTTPResponse:__tostring
|
||||
*/
|
||||
QString to_string();
|
||||
};
|
||||
|
||||
// NOLINTEND(readability-identifier-naming)
|
||||
} // namespace chatterino::lua::api
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue