diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2026-02-26 11:02:55 +0100 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2026-02-26 11:02:55 +0100 |
| commit | 4f97720e4c3944ccf9b9742028dc697c2dd94c5a (patch) | |
| tree | 259ec6c30971f3ca0c7e0f38898ab7f7aa548af9 /src/cancel.cpp | |
| parent | 6b8c83b3bc44b0a1bc186f58de0fea6dfc214c4b (diff) | |
| download | lanes-4f97720e4c3944ccf9b9742028dc697c2dd94c5a.tar.gz lanes-4f97720e4c3944ccf9b9742028dc697c2dd94c5a.tar.bz2 lanes-4f97720e4c3944ccf9b9742028dc697c2dd94c5a.zip | |
change cancel_test() to raise cancel_error on hard-cancels by default
Diffstat (limited to 'src/cancel.cpp')
| -rw-r--r-- | src/cancel.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp index 6812b0d..245065d 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp | |||
| @@ -112,18 +112,28 @@ CancelRequest CheckCancelRequest(lua_State* const L_) | |||
| 112 | // ################################################################################################# | 112 | // ################################################################################################# |
| 113 | 113 | ||
| 114 | //--- | 114 | //--- |
| 115 | // bool = cancel_test() | 115 | // false|"soft" = cancel_test([return_hard]) |
| 116 | // | 116 | // |
| 117 | // Available inside the global namespace of a lane | 117 | // Available inside the global namespace of a lane. |
| 118 | // returns a boolean saying if a cancel request is pending | 118 | // Returns false when no cancel request is pending. |
| 119 | // Returns "soft" when a soft cancel request is pending. | ||
| 120 | // Raises cancel_error when a hard cancel request is pending, | ||
| 121 | // unless the optional boolean argument is true, in which case it returns "hard" instead. | ||
| 119 | // | 122 | // |
| 120 | LUAG_FUNC(cancel_test) | 123 | LUAG_FUNC(cancel_test) |
| 121 | { | 124 | { |
| 122 | CancelRequest const _test{ CheckCancelRequest(L_) }; | 125 | CancelRequest const _test{ CheckCancelRequest(L_) }; |
| 123 | if (_test == CancelRequest::None) { | 126 | if (_test == CancelRequest::None) { |
| 124 | lua_pushboolean(L_, 0); | 127 | lua_pushboolean(L_, 0); |
| 128 | } else if (_test == CancelRequest::Soft) { | ||
| 129 | luaW_pushstring(L_, "soft"); | ||
| 125 | } else { | 130 | } else { |
| 126 | luaW_pushstring(L_, (_test == CancelRequest::Soft) ? "soft" : "hard"); | 131 | // Hard cancel: raise by default, return "hard" if the optional argument is true |
| 132 | if (lua_toboolean(L_, 1)) { | ||
| 133 | luaW_pushstring(L_, "hard"); | ||
| 134 | } else { | ||
| 135 | raise_cancel_error(L_); // doesn't return | ||
| 136 | } | ||
| 127 | } | 137 | } |
| 128 | return 1; | 138 | return 1; |
| 129 | } | 139 | } |
