aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deep_test/deep_test.cpp4
-rw-r--r--src/compat.cpp4
-rw-r--r--src/compat.h2
-rw-r--r--src/deep.cpp4
-rw-r--r--src/deep.h4
-rw-r--r--src/intercopycontext.cpp6
-rw-r--r--src/lanes.cpp3
-rw-r--r--src/linda.cpp4
-rw-r--r--src/linda.h4
-rw-r--r--src/stackindex.hpp6
-rw-r--r--src/unique.hpp12
11 files changed, 36 insertions, 17 deletions
diff --git a/deep_test/deep_test.cpp b/deep_test/deep_test.cpp
index 39352f3..a6c6296 100644
--- a/deep_test/deep_test.cpp
+++ b/deep_test/deep_test.cpp
@@ -129,9 +129,9 @@ static luaL_Reg const deep_mt[] = {
129 129
130int luaD_new_deep(lua_State* L) 130int luaD_new_deep(lua_State* L)
131{ 131{
132 int const nuv{ static_cast<int>(luaL_optinteger(L, 1, 0)) }; 132 UserValueCount const _nuv{ static_cast<int>(luaL_optinteger(L, 1, 0)) };
133 lua_settop(L, 0); 133 lua_settop(L, 0);
134 MyDeepFactory::Instance.pushDeepUserdata(DestState{ L }, nuv); 134 MyDeepFactory::Instance.pushDeepUserdata(DestState{ L }, _nuv);
135 return 1; 135 return 1;
136} 136}
137 137
diff --git a/src/compat.cpp b/src/compat.cpp
index 6bdeecc..1be910f 100644
--- a/src/compat.cpp
+++ b/src/compat.cpp
@@ -5,11 +5,11 @@
5 5
6// ################################################################################################# 6// #################################################################################################
7 7
8int luaG_getalluservalues(lua_State* const L_, StackIndex const idx_) 8UserValueCount luaG_getalluservalues(lua_State* const L_, StackIndex const idx_)
9{ 9{
10 STACK_CHECK_START_REL(L_, 0); 10 STACK_CHECK_START_REL(L_, 0);
11 StackIndex const _idx{ luaG_absindex(L_, idx_) }; 11 StackIndex const _idx{ luaG_absindex(L_, idx_) };
12 int _nuv{ 0 }; 12 UserValueCount _nuv{ 0 };
13 do { 13 do {
14 // we don't know how many uservalues we are going to extract, there might be a lot... 14 // we don't know how many uservalues we are going to extract, there might be a lot...
15 STACK_GROW(L_, 1); 15 STACK_GROW(L_, 1);
diff --git a/src/compat.h b/src/compat.h
index 081e4c7..af014b1 100644
--- a/src/compat.h
+++ b/src/compat.h
@@ -172,7 +172,7 @@ static inline int luaG_dump(lua_State* const L_, lua_Writer const writer_, void*
172 172
173// ################################################################################################# 173// #################################################################################################
174 174
175int luaG_getalluservalues(lua_State* L_, StackIndex idx_); 175UserValueCount luaG_getalluservalues(lua_State* L_, StackIndex idx_);
176 176
177// ################################################################################################# 177// #################################################################################################
178 178
diff --git a/src/deep.cpp b/src/deep.cpp
index a244f8b..0d801a3 100644
--- a/src/deep.cpp
+++ b/src/deep.cpp
@@ -175,7 +175,7 @@ DeepFactory* DeepFactory::LookupFactory(lua_State* const L_, StackIndex const in
175 * Initializes necessary structures if it's the first time 'factory' is being used in 175 * Initializes necessary structures if it's the first time 'factory' is being used in
176 * this Lua state (metatable, registring it). Otherwise, increments the reference count. 176 * this Lua state (metatable, registring it). Otherwise, increments the reference count.
177 */ 177 */
178void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, int const nuv_, LookupMode const mode_, lua_State* const errL_) 178void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, UserValueCount const nuv_, LookupMode const mode_, lua_State* const errL_)
179{ 179{
180 STACK_CHECK_START_REL(L_, 0); 180 STACK_CHECK_START_REL(L_, 0);
181 kDeepProxyCacheRegKey.getSubTableMode(L_, "v"); // L_: DPC 181 kDeepProxyCacheRegKey.getSubTableMode(L_, "v"); // L_: DPC
@@ -302,7 +302,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_,
302 * 302 *
303 * Returns: 'proxy' userdata for accessing the deep data via 'DeepFactory::toDeep()' 303 * Returns: 'proxy' userdata for accessing the deep data via 'DeepFactory::toDeep()'
304 */ 304 */
305void DeepFactory::pushDeepUserdata(DestState const L_, int const nuv_) const 305void DeepFactory::pushDeepUserdata(DestState const L_, UserValueCount const nuv_) const
306{ 306{
307 STACK_GROW(L_, 1); 307 STACK_GROW(L_, 1);
308 STACK_CHECK_START_REL(L_, 0); 308 STACK_CHECK_START_REL(L_, 0);
diff --git a/src/deep.h b/src/deep.h
index 8896698..0ea2712 100644
--- a/src/deep.h
+++ b/src/deep.h
@@ -68,8 +68,8 @@ class DeepFactory
68 static void DeleteDeepObject(lua_State* L_, DeepPrelude* o_); 68 static void DeleteDeepObject(lua_State* L_, DeepPrelude* o_);
69 [[nodiscard]] static bool IsDeepUserdata(lua_State* const L_, StackIndex const idx_); 69 [[nodiscard]] static bool IsDeepUserdata(lua_State* const L_, StackIndex const idx_);
70 [[nodiscard]] static DeepFactory* LookupFactory(lua_State* L_, StackIndex index_, LookupMode mode_); 70 [[nodiscard]] static DeepFactory* LookupFactory(lua_State* L_, StackIndex index_, LookupMode mode_);
71 static void PushDeepProxy(DestState L_, DeepPrelude* o_, int nuv_, LookupMode mode_, lua_State* errL_); 71 static void PushDeepProxy(DestState L_, DeepPrelude* o_, UserValueCount nuv_, LookupMode mode_, lua_State* errL_);
72 void pushDeepUserdata(DestState L_, int nuv_) const; 72 void pushDeepUserdata(DestState L_, UserValueCount nuv_) const;
73 [[nodiscard]] DeepPrelude* toDeep(lua_State* L_, StackIndex index_) const; 73 [[nodiscard]] DeepPrelude* toDeep(lua_State* L_, StackIndex index_) const;
74}; 74};
75 75
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp
index 473ebfd..f54c152 100644
--- a/src/intercopycontext.cpp
+++ b/src/intercopycontext.cpp
@@ -708,7 +708,7 @@ LuaType InterCopyContext::processConversion() const
708 StackIndex const _mt{ luaG_absindex(L1, StackIndex{ -2 }) }; // L1: ... mt __lanesclone 708 StackIndex const _mt{ luaG_absindex(L1, StackIndex{ -2 }) }; // L1: ... mt __lanesclone
709 size_t const userdata_size{ lua_rawlen(L1, _L1_i) }; 709 size_t const userdata_size{ lua_rawlen(L1, _L1_i) };
710 // extract all the uservalues, but don't transfer them yet 710 // extract all the uservalues, but don't transfer them yet
711 int const _nuv{ luaG_getalluservalues(L1, _L1_i) }; // L1: ... mt __lanesclone [uv]* 711 UserValueCount const _nuv{ luaG_getalluservalues(L1, _L1_i) }; // L1: ... mt __lanesclone [uv]*
712 // create the clone userdata with the required number of uservalue slots 712 // create the clone userdata with the required number of uservalue slots
713 void* const _clone{ lua_newuserdatauv(L2, userdata_size, _nuv) }; // L2: ... u 713 void* const _clone{ lua_newuserdatauv(L2, userdata_size, _nuv) }; // L2: ... u
714 // copy the metatable in the target state, and give it to the clone we put there 714 // copy the metatable in the target state, and give it to the clone we put there
@@ -785,7 +785,7 @@ LuaType InterCopyContext::processConversion() const
785 STACK_CHECK_START_REL(L2, 0); 785 STACK_CHECK_START_REL(L2, 0);
786 786
787 // extract all uservalues of the source. unfortunately, the only way to know their count is to iterate until we fail 787 // extract all uservalues of the source. unfortunately, the only way to know their count is to iterate until we fail
788 int const _nuv{ luaG_getalluservalues(L1, L1_i) }; // L1: ... deep ... [uv]* 788 UserValueCount const _nuv{ luaG_getalluservalues(L1, L1_i) }; // L1: ... deep ... [uv]*
789 STACK_CHECK(L1, _nuv); 789 STACK_CHECK(L1, _nuv);
790 790
791 DeepPrelude* const _deep{ *luaG_tofulluserdata<DeepPrelude*>(L1, L1_i) }; 791 DeepPrelude* const _deep{ *luaG_tofulluserdata<DeepPrelude*>(L1, L1_i) };
@@ -867,7 +867,7 @@ LuaType InterCopyContext::processConversion() const
867 size_t const _userdata_size{ lua_rawlen(L1, kIdxTop) }; 867 size_t const _userdata_size{ lua_rawlen(L1, kIdxTop) };
868 { 868 {
869 // extract uservalues (don't transfer them yet) 869 // extract uservalues (don't transfer them yet)
870 int const _nuv{ luaG_getalluservalues(L1, source_i) }; // L1: ... u [uv]* 870 UserValueCount const _nuv{ luaG_getalluservalues(L1, source_i) }; // L1: ... u [uv]*
871 STACK_CHECK(L1, _nuv + 1); 871 STACK_CHECK(L1, _nuv + 1);
872 // create the clone userdata with the required number of uservalue slots 872 // create the clone userdata with the required number of uservalue slots
873 _clone = lua_newuserdatauv(L2, _userdata_size, _nuv); // L2: ... mt u 873 _clone = lua_newuserdatauv(L2, _userdata_size, _nuv); // L2: ... mt u
diff --git a/src/lanes.cpp b/src/lanes.cpp
index 4ebe20c..572d8f9 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -718,7 +718,8 @@ LUAG_FUNC(configure)
718 } 718 }
719 719
720 STACK_CHECK(L_, 2); 720 STACK_CHECK(L_, 2);
721 DeepFactory::PushDeepProxy(DestState{ L_ }, _U->timerLinda, 0, LookupMode::LaneBody, L_); // L_: settings M timerLinda 721 UserValueCount const _nuv{ 0 }; // no uservalue in the linda
722 DeepFactory::PushDeepProxy(DestState{ L_ }, _U->timerLinda, _nuv, LookupMode::LaneBody, L_); // L_: settings M timerLinda
722 lua_setfield(L_, -2, "timerLinda"); // L_: settings M 723 lua_setfield(L_, -2, "timerLinda"); // L_: settings M
723 STACK_CHECK(L_, 2); 724 STACK_CHECK(L_, 2);
724 725
diff --git a/src/linda.cpp b/src/linda.cpp
index bd40f5e..6655ae4 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -981,7 +981,7 @@ LUAG_FUNC(linda)
981 lua_replace(L_, 3); // L_: name group close_handler 981 lua_replace(L_, 3); // L_: name group close_handler
982 982
983 // if we have a __close handler, we need a uservalue slot to store it 983 // if we have a __close handler, we need a uservalue slot to store it
984 int const _nuv{ _closeHandlerIdx ? 1 : 0 }; 984 UserValueCount const _nuv{ _closeHandlerIdx ? 1 : 0 };
985 LindaFactory::Instance.pushDeepUserdata(DestState{ L_ }, _nuv); // L_: name group close_handler linda 985 LindaFactory::Instance.pushDeepUserdata(DestState{ L_ }, _nuv); // L_: name group close_handler linda
986 if (_closeHandlerIdx != 0) { 986 if (_closeHandlerIdx != 0) {
987 lua_replace(L_, 2); // L_: name linda close_handler 987 lua_replace(L_, 2); // L_: name linda close_handler
@@ -996,7 +996,7 @@ LUAG_FUNC(linda)
996 if (_nameIdx > _groupIdx) { 996 if (_nameIdx > _groupIdx) {
997 lua_insert(L_, 1); // L_: name group 997 lua_insert(L_, 1); // L_: name group
998 } 998 }
999 LindaFactory::Instance.pushDeepUserdata(DestState{ L_ }, 0); // L_: name group linda 999 LindaFactory::Instance.pushDeepUserdata(DestState{ L_ }, UserValueCount{ 0 }); // L_: name group linda
1000 return 1; 1000 return 1;
1001 } 1001 }
1002 1002
diff --git a/src/linda.h b/src/linda.h
index ea660d9..c05fb14 100644
--- a/src/linda.h
+++ b/src/linda.h
@@ -30,13 +30,13 @@ class Linda
30 : linda{ linda_ } 30 : linda{ linda_ }
31 , L{ L_ } 31 , L{ L_ }
32 { 32 {
33 [[maybe_unused]] int const _prev{ linda.keeperOperationCount.fetch_add(1, std::memory_order_seq_cst) }; 33 [[maybe_unused]] UnusedInt const _prev{ linda.keeperOperationCount.fetch_add(1, std::memory_order_seq_cst) };
34 } 34 }
35 35
36 public: 36 public:
37 ~KeeperOperationInProgress() 37 ~KeeperOperationInProgress()
38 { 38 {
39 [[maybe_unused]] int const _prev{ linda.keeperOperationCount.fetch_sub(1, std::memory_order_seq_cst) }; 39 [[maybe_unused]] UnusedInt const _prev{ linda.keeperOperationCount.fetch_sub(1, std::memory_order_seq_cst) };
40 } 40 }
41 }; 41 };
42 42
diff --git a/src/stackindex.hpp b/src/stackindex.hpp
index 7c2c17a..1c2ce8c 100644
--- a/src/stackindex.hpp
+++ b/src/stackindex.hpp
@@ -5,6 +5,12 @@
5DECLARE_UNIQUE_TYPE(StackIndex, int); 5DECLARE_UNIQUE_TYPE(StackIndex, int);
6static_assert(std::is_trivial_v<StackIndex>); 6static_assert(std::is_trivial_v<StackIndex>);
7 7
8DECLARE_UNIQUE_TYPE(UserValueCount, int);
9static_assert(std::is_trivial_v<UserValueCount>);
10
11DECLARE_UNIQUE_TYPE(UnusedInt, int);
12static_assert(std::is_trivial_v<UserValueCount>);
13
8// ################################################################################################# 14// #################################################################################################
9 15
10static constexpr StackIndex kIdxRegistry{ LUA_REGISTRYINDEX }; 16static constexpr StackIndex kIdxRegistry{ LUA_REGISTRYINDEX };
diff --git a/src/unique.hpp b/src/unique.hpp
index 829fa49..98a9d48 100644
--- a/src/unique.hpp
+++ b/src/unique.hpp
@@ -43,6 +43,18 @@ class Unique
43 { 43 {
44 return Unique<T, TAG>{ std::exchange(val, val + 1) }; 44 return Unique<T, TAG>{ std::exchange(val, val + 1) };
45 } 45 }
46
47 // pre-decrement
48 auto& operator--() noexcept
49 {
50 --val;
51 return *this;
52 }
53 // post-decrement
54 auto operator--(int) noexcept
55 {
56 return Unique<T, TAG>{ std::exchange(val, val - 1) };
57 }
46}; 58};
47 59
48template <typename T, typename TAG> 60template <typename T, typename TAG>