From 90bcdc8bf5ea305ed50c0746c2f93bc6088c0bbe Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Tue, 8 Oct 2024 13:31:17 +0200 Subject: [PATCH] Give HTTPResponse a to_string --- src/controllers/plugins/api/HTTPResponse.cpp | 12 +++++++++++- src/controllers/plugins/api/HTTPResponse.hpp | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/controllers/plugins/api/HTTPResponse.cpp b/src/controllers/plugins/api/HTTPResponse.cpp index f358f52c4..d4424c4ae 100644 --- a/src/controllers/plugins/api/HTTPResponse.cpp +++ b/src/controllers/plugins/api/HTTPResponse.cpp @@ -17,7 +17,8 @@ void HTTPResponse::createUserType(sol::table &c2) c2.new_usertype( // "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"").arg(*this->status()); + } + return ""; +} + } // namespace chatterino::lua::api #endif diff --git a/src/controllers/plugins/api/HTTPResponse.hpp b/src/controllers/plugins/api/HTTPResponse.hpp index 0f2bfa4c4..a5eb59b4f 100644 --- a/src/controllers/plugins/api/HTTPResponse.hpp +++ b/src/controllers/plugins/api/HTTPResponse.hpp @@ -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