diff options
Diffstat (limited to 'src/linda.cpp')
-rw-r--r-- | src/linda.cpp | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/linda.cpp b/src/linda.cpp index 43fcd20..eb39c0f 100644 --- a/src/linda.cpp +++ b/src/linda.cpp | |||
@@ -48,7 +48,8 @@ namespace { | |||
48 | { | 48 | { |
49 | STACK_CHECK_START_REL(L_, 0); | 49 | STACK_CHECK_START_REL(L_, 0); |
50 | for (int const _i : std::ranges::iota_view{ start_, end_ + 1 }) { | 50 | for (int const _i : std::ranges::iota_view{ start_, end_ + 1 }) { |
51 | switch (LuaType const _t{ luaG_type(L_, _i) }) { | 51 | LuaType const _t{ luaG_type(L_, _i) }; |
52 | switch (_t) { | ||
52 | case LuaType::BOOLEAN: | 53 | case LuaType::BOOLEAN: |
53 | case LuaType::NUMBER: | 54 | case LuaType::NUMBER: |
54 | case LuaType::STRING: | 55 | case LuaType::STRING: |
@@ -81,6 +82,19 @@ namespace { | |||
81 | 82 | ||
82 | // ############################################################################################# | 83 | // ############################################################################################# |
83 | 84 | ||
85 | template <bool OPT> | ||
86 | [[nodiscard]] static inline Linda* ToLinda(lua_State* const L_, int const idx_) | ||
87 | { | ||
88 | Linda* const _linda{ static_cast<Linda*>(LindaFactory::Instance.toDeep(L_, idx_)) }; | ||
89 | if constexpr (!OPT) { | ||
90 | luaL_argcheck(L_, _linda != nullptr, idx_, "expecting a linda object"); // doesn't return if linda is nullptr | ||
91 | LUA_ASSERT(L_, _linda->U == Universe::Get(L_)); | ||
92 | } | ||
93 | return _linda; | ||
94 | } | ||
95 | |||
96 | // ############################################################################################# | ||
97 | |||
84 | /* | 98 | /* |
85 | * string = linda:__tostring( linda_ud) | 99 | * string = linda:__tostring( linda_ud) |
86 | * | 100 | * |
@@ -109,19 +123,6 @@ namespace { | |||
109 | } | 123 | } |
110 | 124 | ||
111 | // ############################################################################################# | 125 | // ############################################################################################# |
112 | |||
113 | template <bool OPT> | ||
114 | [[nodiscard]] static inline Linda* ToLinda(lua_State* const L_, int const idx_) | ||
115 | { | ||
116 | Linda* const _linda{ static_cast<Linda*>(LindaFactory::Instance.toDeep(L_, idx_)) }; | ||
117 | if constexpr (!OPT) { | ||
118 | luaL_argcheck(L_, _linda != nullptr, idx_, "expecting a linda object"); // doesn't return if linda is nullptr | ||
119 | LUA_ASSERT(L_, _linda->U == Universe::Get(L_)); | ||
120 | } | ||
121 | return _linda; | ||
122 | } | ||
123 | |||
124 | // ############################################################################################# | ||
125 | // ############################################################################################# | 126 | // ############################################################################################# |
126 | } // namespace | 127 | } // namespace |
127 | // ################################################################################################# | 128 | // ################################################################################################# |
@@ -195,7 +196,7 @@ int Linda::ProtectedCall(lua_State* const L_, lua_CFunction const f_) | |||
195 | 196 | ||
196 | // acquire the keeper | 197 | // acquire the keeper |
197 | Keeper* const _keeper{ _linda->acquireKeeper() }; | 198 | Keeper* const _keeper{ _linda->acquireKeeper() }; |
198 | KeeperState const _K{ _keeper ? _keeper->K : nullptr }; | 199 | KeeperState const _K{ _keeper ? _keeper->K : KeeperState{ nullptr } }; |
199 | if (_K == nullptr) | 200 | if (_K == nullptr) |
200 | return 0; | 201 | return 0; |
201 | 202 | ||
@@ -574,7 +575,7 @@ LUAG_FUNC(linda_receive) | |||
574 | 575 | ||
575 | Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) }; | 576 | Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) }; |
576 | Keeper* const _keeper{ _linda->whichKeeper() }; | 577 | Keeper* const _keeper{ _linda->whichKeeper() }; |
577 | KeeperState const _K{ _keeper ? _keeper->K : nullptr }; | 578 | KeeperState const _K{ _keeper ? _keeper->K : KeeperState{ nullptr } }; |
578 | if (_K == nullptr) | 579 | if (_K == nullptr) |
579 | return 0; | 580 | return 0; |
580 | 581 | ||
@@ -713,7 +714,7 @@ LUAG_FUNC(linda_send) | |||
713 | { | 714 | { |
714 | Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) }; | 715 | Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) }; |
715 | Keeper* const _keeper{ _linda->whichKeeper() }; | 716 | Keeper* const _keeper{ _linda->whichKeeper() }; |
716 | KeeperState const _K{ _keeper ? _keeper->K : nullptr }; | 717 | KeeperState const _K{ _keeper ? _keeper->K : KeeperState{ nullptr } }; |
717 | if (_K == nullptr) | 718 | if (_K == nullptr) |
718 | return 0; | 719 | return 0; |
719 | 720 | ||