Skip to content

Commit

Permalink
Fix: Take Lua HTTP callbacks as sol::main_protected_function (#5800)
Browse files Browse the repository at this point in the history
Co-authored-by: Nerixyz <[email protected]>
  • Loading branch information
Mm2PL and Nerixyz authored Jan 6, 2025
1 parent f53d92c commit fe05b59
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unversioned

- Bugfix: Fixed a crash relating to Lua HTTP. (#5800)

## 2.5.2

- Bugfix: Fixed a crash in the 7TV EventApi when closing Chatterino. (#5768)
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/plugins/api/HTTPRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

void HTTPRequest::on_error(sol::protected_function func)
void HTTPRequest::on_error(sol::main_protected_function func)
{
this->cbError = std::make_optional(func);
}
Expand All @@ -64,7 +64,7 @@ void HTTPRequest::set_timeout(int 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);
}
Expand Down
12 changes: 6 additions & 6 deletions src/controllers/plugins/api/HTTPRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class HTTPRequest : public std::enable_shared_from_this<HTTPRequest>
int timeout_ = 10'000;
bool done = false;

std::optional<sol::protected_function> cbSuccess;
std::optional<sol::protected_function> cbError;
std::optional<sol::protected_function> cbFinally;
std::optional<sol::main_protected_function> cbSuccess;
std::optional<sol::main_protected_function> cbError;
std::optional<sol::main_protected_function> cbFinally;

public:
// These functions are wrapped so data can be accessed more easily. When a call from Lua comes in:
Expand All @@ -64,23 +64,23 @@ class HTTPRequest : public std::enable_shared_from_this<HTTPRequest>
* @lua@param callback c2.HTTPCallback Function to call when the HTTP request succeeds
* @exposed c2.HTTPRequest:on_success
*/
void on_success(sol::protected_function func);
void on_success(sol::main_protected_function func);

/**
* Sets the failure callback
*
* @lua@param callback c2.HTTPCallback Function to call when the HTTP request fails or returns a non-ok status
* @exposed c2.HTTPRequest:on_error
*/
void on_error(sol::protected_function func);
void on_error(sol::main_protected_function func);

/**
* Sets the finally callback
*
* @lua@param callback fun(): nil Function to call when the HTTP request finishes
* @exposed c2.HTTPRequest:finally
*/
void finally(sol::protected_function func);
void finally(sol::main_protected_function func);

/**
* Sets the timeout
Expand Down

0 comments on commit fe05b59

Please sign in to comment.