Fix: Take Lua HTTP callbacks as sol::main_protected_function (#5800)

Co-authored-by: Nerixyz <nerixdev@outlook.de>
This commit is contained in:
Mm2PL
2025-01-06 22:18:39 +01:00
committed by GitHub
parent f53d92c77a
commit fe05b5994c
3 changed files with 11 additions and 9 deletions
+2
View File
@@ -2,6 +2,8 @@
## Unversioned ## Unversioned
- Bugfix: Fixed a crash relating to Lua HTTP. (#5800)
## 2.5.2 ## 2.5.2
- Bugfix: Fixed a crash in the 7TV EventApi when closing Chatterino. (#5768) - Bugfix: Fixed a crash in the 7TV EventApi when closing Chatterino. (#5768)
+3 -3
View File
@@ -49,12 +49,12 @@ void HTTPRequest::createUserType(sol::table &c2)
); );
} }
void HTTPRequest::on_success(sol::protected_function func) void HTTPRequest::on_success(sol::main_protected_function func)
{ {
this->cbSuccess = std::make_optional(func); this->cbSuccess = std::make_optional(func);
} }
void HTTPRequest::on_error(sol::protected_function func) void HTTPRequest::on_error(sol::main_protected_function func)
{ {
this->cbError = std::make_optional(func); this->cbError = std::make_optional(func);
} }
@@ -64,7 +64,7 @@ void HTTPRequest::set_timeout(int timeout)
this->timeout_ = timeout; this->timeout_ = timeout;
} }
void HTTPRequest::finally(sol::protected_function func) void HTTPRequest::finally(sol::main_protected_function func)
{ {
this->cbFinally = std::make_optional(func); this->cbFinally = std::make_optional(func);
} }
+6 -6
View File
@@ -48,9 +48,9 @@ private:
int timeout_ = 10'000; int timeout_ = 10'000;
bool done = false; bool done = false;
std::optional<sol::protected_function> cbSuccess; std::optional<sol::main_protected_function> cbSuccess;
std::optional<sol::protected_function> cbError; std::optional<sol::main_protected_function> cbError;
std::optional<sol::protected_function> cbFinally; std::optional<sol::main_protected_function> cbFinally;
public: public:
// These functions are wrapped so data can be accessed more easily. When a call from Lua comes in: // These functions are wrapped so data can be accessed more easily. When a call from Lua comes in:
@@ -64,7 +64,7 @@ public:
* @lua@param callback c2.HTTPCallback Function to call when the HTTP request succeeds * @lua@param callback c2.HTTPCallback Function to call when the HTTP request succeeds
* @exposed c2.HTTPRequest:on_success * @exposed c2.HTTPRequest:on_success
*/ */
void on_success(sol::protected_function func); void on_success(sol::main_protected_function func);
/** /**
* Sets the failure callback * Sets the failure callback
@@ -72,7 +72,7 @@ public:
* @lua@param callback c2.HTTPCallback Function to call when the HTTP request fails or returns a non-ok status * @lua@param callback c2.HTTPCallback Function to call when the HTTP request fails or returns a non-ok status
* @exposed c2.HTTPRequest:on_error * @exposed c2.HTTPRequest:on_error
*/ */
void on_error(sol::protected_function func); void on_error(sol::main_protected_function func);
/** /**
* Sets the finally callback * Sets the finally callback
@@ -80,7 +80,7 @@ public:
* @lua@param callback fun(): nil Function to call when the HTTP request finishes * @lua@param callback fun(): nil Function to call when the HTTP request finishes
* @exposed c2.HTTPRequest:finally * @exposed c2.HTTPRequest:finally
*/ */
void finally(sol::protected_function func); void finally(sol::main_protected_function func);
/** /**
* Sets the timeout * Sets the timeout