aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/linda.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/linda.cpp b/src/linda.cpp
index bd3026d..33d9f0b 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -37,30 +37,34 @@ THE SOFTWARE.
37#include "tools.h" 37#include "tools.h"
38 38
39#include <functional> 39#include <functional>
40#include <ranges>
40 41
41// ################################################################################################# 42// #################################################################################################
42 43
43static void check_key_types(lua_State* L_, int start_, int end_) 44static void check_key_types(lua_State* const L_, int const start_, int const end_)
44{ 45{
45 for (int _i{ start_ }; _i <= end_; ++_i) { 46 for (int const _i : std::ranges::iota_view{ start_, end_ + 1 }) {
46 LuaType const t{ luaG_type(L_, _i) }; 47 switch (LuaType const _t{ luaG_type(L_, _i) }) {
47 switch (t) {
48 case LuaType::BOOLEAN: 48 case LuaType::BOOLEAN:
49 case LuaType::NUMBER: 49 case LuaType::NUMBER:
50 case LuaType::STRING: 50 case LuaType::STRING:
51 continue; 51 break;
52 52
53 case LuaType::LIGHTUSERDATA: 53 case LuaType::LIGHTUSERDATA:
54 static constexpr std::array<std::reference_wrapper<UniqueKey const>, 3> kKeysToCheck{ kLindaBatched, kCancelError, kNilSentinel }; 54 {
55 for (UniqueKey const& _key : kKeysToCheck) { 55 static constexpr std::array<std::reference_wrapper<UniqueKey const>, 3> kKeysToCheck{ kLindaBatched, kCancelError, kNilSentinel };
56 if (_key.equals(L_, _i)) { 56 for (UniqueKey const& _key : kKeysToCheck) {
57 raise_luaL_error(L_, "argument #%d: can't use %s as a key", _i, _key.debugName.data()); 57 if (_key.equals(L_, _i)) {
58 break; 58 raise_luaL_error(L_, "argument #%d: can't use %s as a key", _i, _key.debugName.data());
59 break;
60 }
59 } 61 }
60 } 62 }
61 break; 63 break;
64
65 default:
66 raise_luaL_error(L_, "argument #%d: invalid key type (not a boolean, string, number or light userdata)", _i);
62 } 67 }
63 raise_luaL_error(L_, "argument #%d: invalid key type (not a boolean, string, number or light userdata)", _i);
64 } 68 }
65} 69}
66 70
@@ -496,7 +500,7 @@ LUAG_FUNC(linda_receive)
496 return 0; 500 return 0;
497 501
498 CancelRequest _cancel{ CancelRequest::None }; 502 CancelRequest _cancel{ CancelRequest::None };
499 KeeperCallResult _pushed; 503 KeeperCallResult _pushed{};
500 STACK_CHECK_START_REL(_KL, 0); 504 STACK_CHECK_START_REL(_KL, 0);
501 for (bool _try_again{ true };;) { 505 for (bool _try_again{ true };;) {
502 if (_lane != nullptr) { 506 if (_lane != nullptr) {