diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-11-20 18:03:33 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-11-20 18:03:33 +0100 |
commit | 0f6f3c207c46fa28059403e5f16af774d20c7ea2 (patch) | |
tree | 8031145bb2534c33ca0f2c65b9de85696c8a8ee0 /deep_test | |
parent | 304e4dfabe4555dff4aa72e75b677405fd30d1b3 (diff) | |
download | lanes-0f6f3c207c46fa28059403e5f16af774d20c7ea2.tar.gz lanes-0f6f3c207c46fa28059403e5f16af774d20c7ea2.tar.bz2 lanes-0f6f3c207c46fa28059403e5f16af774d20c7ea2.zip |
More [[nodiscard]] boyscouting
Diffstat (limited to 'deep_test')
-rw-r--r-- | deep_test/deep_test.cpp | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/deep_test/deep_test.cpp b/deep_test/deep_test.cpp index db91198..119e992 100644 --- a/deep_test/deep_test.cpp +++ b/deep_test/deep_test.cpp | |||
@@ -13,8 +13,10 @@ class MyDeepFactory : public DeepFactory | |||
13 | luaL_getmetatable(L_, "deep"); | 13 | luaL_getmetatable(L_, "deep"); |
14 | } | 14 | } |
15 | void deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* o_) const override; | 15 | void deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* o_) const override; |
16 | [[nodiscard]] DeepPrelude* newDeepObjectInternal(lua_State* const L_) const override; | 16 | [[nodiscard]] |
17 | [[nodiscard]] std::string_view moduleName() const override { return std::string_view{ "deep_test" }; } | 17 | DeepPrelude* newDeepObjectInternal(lua_State* const L_) const override; |
18 | [[nodiscard]] | ||
19 | std::string_view moduleName() const override { return std::string_view{ "deep_test" }; } | ||
18 | }; | 20 | }; |
19 | /*static*/ MyDeepFactory MyDeepFactory::Instance{}; | 21 | /*static*/ MyDeepFactory MyDeepFactory::Instance{}; |
20 | 22 | ||
@@ -45,7 +47,8 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* c | |||
45 | 47 | ||
46 | // ################################################################################################# | 48 | // ################################################################################################# |
47 | 49 | ||
48 | [[nodiscard]] static int deep_gc(lua_State* L) | 50 | [[nodiscard]] |
51 | static int deep_gc(lua_State* L) | ||
49 | { | 52 | { |
50 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; | 53 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; |
51 | luaL_argcheck(L, 1, !_self->inUse.load(), "being collected while in use!"); | 54 | luaL_argcheck(L, 1, !_self->inUse.load(), "being collected while in use!"); |
@@ -54,7 +57,8 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* c | |||
54 | 57 | ||
55 | // ################################################################################################# | 58 | // ################################################################################################# |
56 | 59 | ||
57 | [[nodiscard]] static int deep_tostring(lua_State* L) | 60 | [[nodiscard]] |
61 | static int deep_tostring(lua_State* L) | ||
58 | { | 62 | { |
59 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; | 63 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; |
60 | _self->inUse.fetch_add(1, std::memory_order_seq_cst); | 64 | _self->inUse.fetch_add(1, std::memory_order_seq_cst); |
@@ -66,7 +70,8 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* c | |||
66 | // ################################################################################################# | 70 | // ################################################################################################# |
67 | 71 | ||
68 | // won't actually do anything as deep userdata don't have uservalue slots | 72 | // won't actually do anything as deep userdata don't have uservalue slots |
69 | [[nodiscard]] static int deep_getuv(lua_State* L) | 73 | [[nodiscard]] |
74 | static int deep_getuv(lua_State* L) | ||
70 | { | 75 | { |
71 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; | 76 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; |
72 | _self->inUse.fetch_add(1, std::memory_order_seq_cst); | 77 | _self->inUse.fetch_add(1, std::memory_order_seq_cst); |
@@ -78,7 +83,8 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* c | |||
78 | 83 | ||
79 | // ################################################################################################# | 84 | // ################################################################################################# |
80 | 85 | ||
81 | [[nodiscard]] static int deep_invoke(lua_State* L) | 86 | [[nodiscard]] |
87 | static int deep_invoke(lua_State* L) | ||
82 | { | 88 | { |
83 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; | 89 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; |
84 | luaL_argcheck(L, 2, lua_gettop(L) >= 2, "need something to call"); | 90 | luaL_argcheck(L, 2, lua_gettop(L) >= 2, "need something to call"); |
@@ -90,7 +96,8 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* c | |||
90 | 96 | ||
91 | // ################################################################################################# | 97 | // ################################################################################################# |
92 | 98 | ||
93 | [[nodiscard]] static int deep_set(lua_State* const L_) | 99 | [[nodiscard]] |
100 | static int deep_set(lua_State* const L_) | ||
94 | { | 101 | { |
95 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L_, StackIndex{ 1 })) }; | 102 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L_, StackIndex{ 1 })) }; |
96 | _self->inUse.fetch_add(1, std::memory_order_seq_cst); | 103 | _self->inUse.fetch_add(1, std::memory_order_seq_cst); |
@@ -102,7 +109,8 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* c | |||
102 | 109 | ||
103 | // ################################################################################################# | 110 | // ################################################################################################# |
104 | 111 | ||
105 | [[nodiscard]] static int deep_setuv(lua_State* L) | 112 | [[nodiscard]] |
113 | static int deep_setuv(lua_State* L) | ||
106 | { | 114 | { |
107 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; | 115 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, StackIndex{ 1 })) }; |
108 | _self->inUse.fetch_add(1, std::memory_order_seq_cst); | 116 | _self->inUse.fetch_add(1, std::memory_order_seq_cst); |
@@ -145,7 +153,8 @@ struct MyClonableUserdata | |||
145 | 153 | ||
146 | // ################################################################################################# | 154 | // ################################################################################################# |
147 | 155 | ||
148 | [[nodiscard]] static int clonable_set(lua_State* L) | 156 | [[nodiscard]] |
157 | static int clonable_set(lua_State* L) | ||
149 | { | 158 | { |
150 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); | 159 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); |
151 | lua_Integer i = lua_tointeger(L, 2); | 160 | lua_Integer i = lua_tointeger(L, 2); |
@@ -155,7 +164,8 @@ struct MyClonableUserdata | |||
155 | 164 | ||
156 | // ################################################################################################# | 165 | // ################################################################################################# |
157 | 166 | ||
158 | [[nodiscard]] static int clonable_setuv(lua_State* L) | 167 | [[nodiscard]] |
168 | static int clonable_setuv(lua_State* L) | ||
159 | { | 169 | { |
160 | MyClonableUserdata* const _self{ static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)) }; | 170 | MyClonableUserdata* const _self{ static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)) }; |
161 | UserValueIndex const _uv{ static_cast<UserValueIndex::type>(luaL_optinteger(L, 2, 1)) }; | 171 | UserValueIndex const _uv{ static_cast<UserValueIndex::type>(luaL_optinteger(L, 2, 1)) }; |
@@ -166,7 +176,8 @@ struct MyClonableUserdata | |||
166 | 176 | ||
167 | // ################################################################################################# | 177 | // ################################################################################################# |
168 | 178 | ||
169 | [[nodiscard]] static int clonable_getuv(lua_State* L) | 179 | [[nodiscard]] |
180 | static int clonable_getuv(lua_State* L) | ||
170 | { | 181 | { |
171 | MyClonableUserdata* const _self{ static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)) }; | 182 | MyClonableUserdata* const _self{ static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)) }; |
172 | UserValueIndex const _uv{ static_cast<UserValueIndex::type>(luaL_optinteger(L, 2, 1)) }; | 183 | UserValueIndex const _uv{ static_cast<UserValueIndex::type>(luaL_optinteger(L, 2, 1)) }; |
@@ -176,7 +187,8 @@ struct MyClonableUserdata | |||
176 | 187 | ||
177 | // ################################################################################################# | 188 | // ################################################################################################# |
178 | 189 | ||
179 | [[nodiscard]] static int clonable_tostring(lua_State* L) | 190 | [[nodiscard]] |
191 | static int clonable_tostring(lua_State* L) | ||
180 | { | 192 | { |
181 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); | 193 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); |
182 | luaG_pushstring(L, "%p:clonable(%d)", lua_topointer(L, 1), self->val); | 194 | luaG_pushstring(L, "%p:clonable(%d)", lua_topointer(L, 1), self->val); |
@@ -185,7 +197,8 @@ struct MyClonableUserdata | |||
185 | 197 | ||
186 | // ################################################################################################# | 198 | // ################################################################################################# |
187 | 199 | ||
188 | [[nodiscard]] static int clonable_gc(lua_State* L) | 200 | [[nodiscard]] |
201 | static int clonable_gc(lua_State* L) | ||
189 | { | 202 | { |
190 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); | 203 | MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); |
191 | return 0; | 204 | return 0; |
@@ -194,7 +207,8 @@ struct MyClonableUserdata | |||
194 | // ################################################################################################# | 207 | // ################################################################################################# |
195 | 208 | ||
196 | // this is all we need to make a userdata lanes-clonable. no dependency on Lanes code. | 209 | // this is all we need to make a userdata lanes-clonable. no dependency on Lanes code. |
197 | [[nodiscard]] static int clonable_lanesclone(lua_State* L) | 210 | [[nodiscard]] |
211 | static int clonable_lanesclone(lua_State* L) | ||
198 | { | 212 | { |
199 | switch (lua_gettop(L)) { | 213 | switch (lua_gettop(L)) { |
200 | case 3: | 214 | case 3: |