aboutsummaryrefslogtreecommitdiff
path: root/src/lindafactory.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lindafactory.cpp24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/lindafactory.cpp b/src/lindafactory.cpp
index 3ee0ba4..1a8782e 100644
--- a/src/lindafactory.cpp
+++ b/src/lindafactory.cpp
@@ -2,7 +2,7 @@
2 * LINDAFACTORY.CPP Copyright (c) 2024-, Benoit Germain 2 * LINDAFACTORY.CPP Copyright (c) 2024-, Benoit Germain
3 * 3 *
4 * Linda deep userdata factory 4 * Linda deep userdata factory
5*/ 5 */
6 6
7/* 7/*
8=============================================================================== 8===============================================================================
@@ -69,8 +69,7 @@ void LindaFactory::deleteDeepObjectInternal(lua_State* L_, DeepPrelude* o_) cons
69 LUA_ASSERT(L_, linda); 69 LUA_ASSERT(L_, linda);
70 Keeper* const myK{ linda->whichKeeper() }; 70 Keeper* const myK{ linda->whichKeeper() };
71 // if collected after the universe, keepers are already destroyed, and there is nothing to clear 71 // if collected after the universe, keepers are already destroyed, and there is nothing to clear
72 if (myK) 72 if (myK) {
73 {
74 // if collected from my own keeper, we can't acquire/release it 73 // if collected from my own keeper, we can't acquire/release it
75 // because we are already inside a protected area, and trying to do so would deadlock! 74 // because we are already inside a protected area, and trying to do so would deadlock!
76 bool const need_acquire_release{ myK->L != L_ }; 75 bool const need_acquire_release{ myK->L != L_ };
@@ -79,8 +78,7 @@ void LindaFactory::deleteDeepObjectInternal(lua_State* L_, DeepPrelude* o_) cons
79 // hopefully this won't ever raise an error as we would jump to the closest pcall site while forgetting to release the keeper mutex... 78 // hopefully this won't ever raise an error as we would jump to the closest pcall site while forgetting to release the keeper mutex...
80 [[maybe_unused]] KeeperCallResult const result{ keeper_call(linda->U, K->L, KEEPER_API(clear), L_, linda, 0) }; 79 [[maybe_unused]] KeeperCallResult const result{ keeper_call(linda->U, K->L, KEEPER_API(clear), L_, linda, 0) };
81 LUA_ASSERT(L_, result.has_value() && result.value() == 0); 80 LUA_ASSERT(L_, result.has_value() && result.value() == 0);
82 if (need_acquire_release) 81 if (need_acquire_release) {
83 {
84 linda->releaseKeeper(K); 82 linda->releaseKeeper(K);
85 } 83 }
86 } 84 }
@@ -106,23 +104,19 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L_) const
106 char const* linda_name{ nullptr }; 104 char const* linda_name{ nullptr };
107 LindaGroup linda_group{ 0 }; 105 LindaGroup linda_group{ 0 };
108 // should have a string and/or a number of the stack as parameters (name and group) 106 // should have a string and/or a number of the stack as parameters (name and group)
109 switch (lua_gettop(L_)) 107 switch (lua_gettop(L_)) {
110 { 108 default: // 0
111 default: // 0
112 break; 109 break;
113 110
114 case 1: // 1 parameter, either a name or a group 111 case 1: // 1 parameter, either a name or a group
115 if (lua_type(L_, -1) == LUA_TSTRING) 112 if (lua_type(L_, -1) == LUA_TSTRING) {
116 {
117 linda_name = lua_tolstring(L_, -1, &name_len); 113 linda_name = lua_tolstring(L_, -1, &name_len);
118 } 114 } else {
119 else
120 {
121 linda_group = LindaGroup{ static_cast<int>(lua_tointeger(L_, -1)) }; 115 linda_group = LindaGroup{ static_cast<int>(lua_tointeger(L_, -1)) };
122 } 116 }
123 break; 117 break;
124 118
125 case 2: // 2 parameters, a name and group, in that order 119 case 2: // 2 parameters, a name and group, in that order
126 linda_name = lua_tolstring(L_, -2, &name_len); 120 linda_name = lua_tolstring(L_, -2, &name_len);
127 linda_group = LindaGroup{ static_cast<int>(lua_tointeger(L_, -1)) }; 121 linda_group = LindaGroup{ static_cast<int>(lua_tointeger(L_, -1)) };
128 break; 122 break;