Give HTTPResponse a to_string

This commit is contained in:
Mm2PL 2024-10-08 13:31:17 +02:00
parent 072003c0fe
commit 90bcdc8bf5
No known key found for this signature in database
GPG key ID: 94AC9B80EFA15ED9
2 changed files with 19 additions and 1 deletions

View file

@ -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

View file

@ -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