aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cancel.cpp18
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//
120LUAG_FUNC(cancel_test) 123LUAG_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}