aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deep_test/deep_test.cpp278
-rw-r--r--src/cancel.cpp12
-rw-r--r--src/cancel.h4
-rw-r--r--src/compat.cpp6
-rw-r--r--src/deep.cpp12
-rw-r--r--src/deep.h10
-rw-r--r--src/keeper.cpp58
-rw-r--r--src/keeper.h26
-rw-r--r--src/lanes.cpp55
-rw-r--r--src/lanes.h2
-rw-r--r--src/lanes_private.h11
-rw-r--r--src/linda.cpp12
-rw-r--r--src/macros_and_utils.h15
-rw-r--r--src/state.cpp6
-rw-r--r--src/state.h4
-rw-r--r--src/threading.cpp4
-rw-r--r--src/threading_osx.h10
-rw-r--r--src/tools.cpp260
-rw-r--r--src/tools.h10
-rw-r--r--src/universe.h10
20 files changed, 410 insertions, 395 deletions
diff --git a/deep_test/deep_test.cpp b/deep_test/deep_test.cpp
index 7c8180f..3467939 100644
--- a/deep_test/deep_test.cpp
+++ b/deep_test/deep_test.cpp
@@ -10,114 +10,114 @@
10// a lanes-deep userdata. needs DeepPrelude and luaG_newdeepuserdata from Lanes code. 10// a lanes-deep userdata. needs DeepPrelude and luaG_newdeepuserdata from Lanes code.
11struct MyDeepUserdata : public DeepPrelude // Deep userdata MUST start with a DeepPrelude 11struct MyDeepUserdata : public DeepPrelude // Deep userdata MUST start with a DeepPrelude
12{ 12{
13 lua_Integer val{ 0 }; 13 lua_Integer val{ 0 };
14}; 14};
15 15
16// ################################################################################################ 16// ################################################################################################
17 17
18static void* deep_test_id( lua_State* L, DeepOp op_) 18[[nodiscard]] static void* deep_test_id(lua_State* L, DeepOp op_)
19{ 19{
20 switch( op_) 20 switch( op_)
21 { 21 {
22 case DeepOp::New: 22 case DeepOp::New:
23 { 23 {
24 MyDeepUserdata* deep_test = new MyDeepUserdata; 24 MyDeepUserdata* deep_test = new MyDeepUserdata;
25 return deep_test; 25 return deep_test;
26 } 26 }
27 27
28 case DeepOp::Delete: 28 case DeepOp::Delete:
29 { 29 {
30 MyDeepUserdata* deep_test = static_cast<MyDeepUserdata*>(lua_touserdata( L, 1)); 30 MyDeepUserdata* deep_test = static_cast<MyDeepUserdata*>(lua_touserdata( L, 1));
31 delete deep_test; 31 delete deep_test;
32 return nullptr; 32 return nullptr;
33 } 33 }
34 34
35 case DeepOp::Metatable: 35 case DeepOp::Metatable:
36 { 36 {
37 luaL_getmetatable( L, "deep"); // mt 37 luaL_getmetatable( L, "deep"); // mt
38 return nullptr; 38 return nullptr;
39 } 39 }
40 40
41 case DeepOp::Module: 41 case DeepOp::Module:
42 return (void*)"deep_test"; 42 return (void*)"deep_test";
43 43
44 default: 44 default:
45 { 45 {
46 return nullptr; 46 return nullptr;
47 } 47 }
48 } 48 }
49} 49}
50 50
51// ################################################################################################ 51// ################################################################################################
52 52
53static int deep_set( lua_State* L) 53[[nodiscard]] static int deep_set(lua_State* L)
54{ 54{
55 MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1)); 55 MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1));
56 lua_Integer i = lua_tointeger( L, 2); 56 lua_Integer i = lua_tointeger( L, 2);
57 self->val = i; 57 self->val = i;
58 return 0; 58 return 0;
59} 59}
60 60
61// ################################################################################################ 61// ################################################################################################
62 62
63// won't actually do anything as deep userdata don't have uservalue slots 63// won't actually do anything as deep userdata don't have uservalue slots
64static int deep_setuv( lua_State* L) 64[[nodiscard]] static int deep_setuv(lua_State* L)
65{ 65{
66 MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1)); 66 MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1));
67 int uv = (int) luaL_optinteger(L, 2, 1); 67 int uv = (int) luaL_optinteger(L, 2, 1);
68 lua_settop( L, 3); 68 lua_settop( L, 3);
69 lua_pushboolean( L, lua_setiuservalue( L, 1, uv) != 0); 69 lua_pushboolean( L, lua_setiuservalue( L, 1, uv) != 0);
70 return 1; 70 return 1;
71} 71}
72 72
73// ################################################################################################ 73// ################################################################################################
74 74
75// won't actually do anything as deep userdata don't have uservalue slots 75// won't actually do anything as deep userdata don't have uservalue slots
76static int deep_getuv( lua_State* L) 76[[nodiscard]] static int deep_getuv(lua_State* L)
77{ 77{
78 MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1)); 78 MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1));
79 int uv = (int) luaL_optinteger(L, 2, 1); 79 int uv = (int) luaL_optinteger(L, 2, 1);
80 lua_getiuservalue( L, 1, uv); 80 lua_getiuservalue( L, 1, uv);
81 return 1; 81 return 1;
82} 82}
83 83
84// ################################################################################################ 84// ################################################################################################
85 85
86static int deep_tostring( lua_State* L) 86[[nodiscard]] static int deep_tostring(lua_State* L)
87{ 87{
88 MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1)); 88 MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1));
89 lua_pushfstring(L, "%p:deep(%d)", lua_topointer(L, 1), self->val); 89 lua_pushfstring(L, "%p:deep(%d)", lua_topointer(L, 1), self->val);
90 return 1; 90 return 1;
91} 91}
92 92
93// ################################################################################################ 93// ################################################################################################
94 94
95static int deep_gc( lua_State* L) 95[[nodiscard]] static int deep_gc(lua_State* L)
96{ 96{
97 MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1)); 97 MyDeepUserdata* self = static_cast<MyDeepUserdata*>(luaG_todeep(L, deep_test_id, 1));
98 return 0; 98 return 0;
99} 99}
100 100
101// ################################################################################################ 101// ################################################################################################
102 102
103static luaL_Reg const deep_mt[] = 103static luaL_Reg const deep_mt[] =
104{ 104{
105 { "__tostring", deep_tostring}, 105 { "__tostring", deep_tostring},
106 { "__gc", deep_gc}, 106 { "__gc", deep_gc},
107 { "set", deep_set}, 107 { "set", deep_set},
108 { "setuv", deep_setuv}, 108 { "setuv", deep_setuv},
109 { "getuv", deep_getuv}, 109 { "getuv", deep_getuv},
110 { nullptr, nullptr } 110 { nullptr, nullptr }
111}; 111};
112 112
113// ################################################################################################ 113// ################################################################################################
114 114
115int luaD_new_deep( lua_State* L) 115int luaD_new_deep( lua_State* L)
116{ 116{
117 int nuv = (int) luaL_optinteger( L, 1, 0); 117 int const nuv{ static_cast<int>(luaL_optinteger(L, 1, 0)) };
118 // no additional parameter to luaG_newdeepuserdata! 118 // no additional parameter to luaG_newdeepuserdata!
119 lua_settop( L, 0); 119 lua_settop(L, 0);
120 return luaG_newdeepuserdata( L, deep_test_id, nuv); 120 return luaG_newdeepuserdata(Dest{ L }, deep_test_id, nuv);
121} 121}
122 122
123// ################################################################################################ 123// ################################################################################################
@@ -125,101 +125,101 @@ int luaD_new_deep( lua_State* L)
125 125
126struct MyClonableUserdata 126struct MyClonableUserdata
127{ 127{
128 lua_Integer val; 128 lua_Integer val;
129}; 129};
130 130
131// ################################################################################################ 131// ################################################################################################
132 132
133static int clonable_set( lua_State* L) 133[[nodiscard]] static int clonable_set(lua_State* L)
134{ 134{
135 MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); 135 MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1));
136 lua_Integer i = lua_tointeger(L, 2); 136 lua_Integer i = lua_tointeger(L, 2);
137 self->val = i; 137 self->val = i;
138 return 0; 138 return 0;
139} 139}
140 140
141// ################################################################################################ 141// ################################################################################################
142 142
143static int clonable_setuv( lua_State* L) 143[[nodiscard]] static int clonable_setuv(lua_State* L)
144{ 144{
145 MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); 145 MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1));
146 int uv = (int) luaL_optinteger(L, 2, 1); 146 int uv = (int) luaL_optinteger(L, 2, 1);
147 lua_settop( L, 3); 147 lua_settop( L, 3);
148 lua_pushboolean( L, lua_setiuservalue( L, 1, uv) != 0); 148 lua_pushboolean( L, lua_setiuservalue( L, 1, uv) != 0);
149 return 1; 149 return 1;
150} 150}
151 151
152// ################################################################################################ 152// ################################################################################################
153 153
154static int clonable_getuv( lua_State* L) 154[[nodiscard]] static int clonable_getuv(lua_State* L)
155{ 155{
156 MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); 156 MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1));
157 int uv = (int) luaL_optinteger(L, 2, 1); 157 int uv = (int) luaL_optinteger(L, 2, 1);
158 lua_getiuservalue( L, 1, uv); 158 lua_getiuservalue( L, 1, uv);
159 return 1; 159 return 1;
160} 160}
161 161
162// ################################################################################################ 162// ################################################################################################
163 163
164static int clonable_tostring(lua_State* L) 164[[nodiscard]] static int clonable_tostring(lua_State* L)
165{ 165{
166 MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); 166 MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1));
167 lua_pushfstring(L, "%p:clonable(%d)", lua_topointer(L, 1), self->val); 167 lua_pushfstring(L, "%p:clonable(%d)", lua_topointer(L, 1), self->val);
168 return 1; 168 return 1;
169} 169}
170 170
171// ################################################################################################ 171// ################################################################################################
172 172
173static int clonable_gc( lua_State* L) 173[[nodiscard]] static int clonable_gc(lua_State* L)
174{ 174{
175 MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); 175 MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1));
176 return 0; 176 return 0;
177} 177}
178 178
179// ################################################################################################ 179// ################################################################################################
180 180
181// this is all we need to make a userdata lanes-clonable. no dependency on Lanes code. 181// this is all we need to make a userdata lanes-clonable. no dependency on Lanes code.
182static int clonable_lanesclone( lua_State* L) 182[[nodiscard]] static int clonable_lanesclone(lua_State* L)
183{ 183{
184 switch( lua_gettop( L)) 184 switch( lua_gettop( L))
185 { 185 {
186 case 3: 186 case 3:
187 { 187 {
188 MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1)); 188 MyClonableUserdata* self = static_cast<MyClonableUserdata*>(lua_touserdata(L, 1));
189 MyClonableUserdata* from = static_cast<MyClonableUserdata*>(lua_touserdata(L, 2)); 189 MyClonableUserdata* from = static_cast<MyClonableUserdata*>(lua_touserdata(L, 2));
190 size_t len = lua_tointeger( L, 3); 190 size_t len = lua_tointeger( L, 3);
191 assert( len == sizeof(MyClonableUserdata)); 191 assert( len == sizeof(MyClonableUserdata));
192 *self = *from; 192 *self = *from;
193 } 193 }
194 return 0; 194 return 0;
195 195
196 default: 196 default:
197 (void) luaL_error( L, "Lanes called clonable_lanesclone with unexpected parameters"); 197 (void) luaL_error( L, "Lanes called clonable_lanesclone with unexpected parameters");
198 } 198 }
199 return 0; 199 return 0;
200} 200}
201 201
202// ################################################################################################ 202// ################################################################################################
203 203
204static luaL_Reg const clonable_mt[] = 204static luaL_Reg const clonable_mt[] =
205{ 205{
206 { "__tostring", clonable_tostring}, 206 { "__tostring", clonable_tostring},
207 { "__gc", clonable_gc}, 207 { "__gc", clonable_gc},
208 { "__lanesclone", clonable_lanesclone}, 208 { "__lanesclone", clonable_lanesclone},
209 { "set", clonable_set}, 209 { "set", clonable_set},
210 { "setuv", clonable_setuv}, 210 { "setuv", clonable_setuv},
211 { "getuv", clonable_getuv}, 211 { "getuv", clonable_getuv},
212 { nullptr, nullptr } 212 { nullptr, nullptr }
213}; 213};
214 214
215// ################################################################################################ 215// ################################################################################################
216 216
217int luaD_new_clonable( lua_State* L) 217int luaD_new_clonable( lua_State* L)
218{ 218{
219 int nuv = (int) luaL_optinteger( L, 1, 1); 219 int const nuv{ static_cast<int>(luaL_optinteger(L, 1, 1)) };
220 lua_newuserdatauv( L, sizeof(MyClonableUserdata), nuv); 220 lua_newuserdatauv( L, sizeof(MyClonableUserdata), nuv);
221 luaL_setmetatable( L, "clonable"); 221 luaL_setmetatable( L, "clonable");
222 return 1; 222 return 1;
223} 223}
224 224
225// ################################################################################################ 225// ################################################################################################
@@ -227,33 +227,33 @@ int luaD_new_clonable( lua_State* L)
227 227
228static luaL_Reg const deep_module[] = 228static luaL_Reg const deep_module[] =
229{ 229{
230 { "new_deep", luaD_new_deep}, 230 { "new_deep", luaD_new_deep},
231 { "new_clonable", luaD_new_clonable}, 231 { "new_clonable", luaD_new_clonable},
232 { nullptr, nullptr } 232 { nullptr, nullptr }
233}; 233};
234 234
235// ################################################################################################ 235// ################################################################################################
236 236
237LANES_API int luaopen_deep_test(lua_State* L) 237LANES_API int luaopen_deep_test(lua_State* L)
238{ 238{
239 luaL_newlib( L, deep_module); // M 239 luaL_newlib( L, deep_module); // M
240 240
241 // preregister the metatables for the types we can instantiate so that Lanes can know about them 241 // preregister the metatables for the types we can instantiate so that Lanes can know about them
242 if( luaL_newmetatable( L, "clonable")) // M mt 242 if( luaL_newmetatable( L, "clonable")) // M mt
243 { 243 {
244 luaL_setfuncs( L, clonable_mt, 0); 244 luaL_setfuncs( L, clonable_mt, 0);
245 lua_pushvalue(L, -1); // M mt mt 245 lua_pushvalue(L, -1); // M mt mt
246 lua_setfield(L, -2, "__index"); // M mt 246 lua_setfield(L, -2, "__index"); // M mt
247 } 247 }
248 lua_setfield(L, -2, "__clonableMT"); // M 248 lua_setfield(L, -2, "__clonableMT"); // M
249 249
250 if( luaL_newmetatable( L, "deep")) // mt 250 if( luaL_newmetatable( L, "deep")) // mt
251 { 251 {
252 luaL_setfuncs( L, deep_mt, 0); 252 luaL_setfuncs( L, deep_mt, 0);
253 lua_pushvalue(L, -1); // mt mt 253 lua_pushvalue(L, -1); // mt mt
254 lua_setfield(L, -2, "__index"); // mt 254 lua_setfield(L, -2, "__index"); // mt
255 } 255 }
256 lua_setfield(L, -2, "__deepMT"); // M 256 lua_setfield(L, -2, "__deepMT"); // M
257 257
258 return 1; 258 return 1;
259} 259}
diff --git a/src/cancel.cpp b/src/cancel.cpp
index e08e975..2f3c22e 100644
--- a/src/cancel.cpp
+++ b/src/cancel.cpp
@@ -51,7 +51,7 @@ THE SOFTWARE.
51* Returns CANCEL_SOFT/HARD if any locks are to be exited, and 'raise_cancel_error()' called, 51* Returns CANCEL_SOFT/HARD if any locks are to be exited, and 'raise_cancel_error()' called,
52* to make execution of the lane end. 52* to make execution of the lane end.
53*/ 53*/
54static inline CancelRequest cancel_test(lua_State* L) 54[[nodiscard]] static inline CancelRequest cancel_test(lua_State* L)
55{ 55{
56 Lane* const lane{ LANE_POINTER_REGKEY.readLightUserDataValue<Lane>(L) }; 56 Lane* const lane{ LANE_POINTER_REGKEY.readLightUserDataValue<Lane>(L) };
57 // 'lane' is nullptr for the original main state (and no-one can cancel that) 57 // 'lane' is nullptr for the original main state (and no-one can cancel that)
@@ -76,7 +76,7 @@ LUAG_FUNC( cancel_test)
76// ################################################################################################ 76// ################################################################################################
77// ################################################################################################ 77// ################################################################################################
78 78
79static void cancel_hook(lua_State* L, [[maybe_unused]] lua_Debug* ar) 79[[nodiscard]] static void cancel_hook(lua_State* L, [[maybe_unused]] lua_Debug* ar)
80{ 80{
81 DEBUGSPEW_CODE(fprintf(stderr, "cancel_hook\n")); 81 DEBUGSPEW_CODE(fprintf(stderr, "cancel_hook\n"));
82 if (cancel_test(L) != CancelRequest::None) 82 if (cancel_test(L) != CancelRequest::None)
@@ -108,7 +108,7 @@ static void cancel_hook(lua_State* L, [[maybe_unused]] lua_Debug* ar)
108 108
109// ################################################################################################ 109// ################################################################################################
110 110
111static CancelResult thread_cancel_soft(Lane* lane_, lua_Duration duration_, bool wake_lane_) 111[[nodiscard]] static CancelResult thread_cancel_soft(Lane* lane_, lua_Duration duration_, bool wake_lane_)
112{ 112{
113 lane_->cancel_request = CancelRequest::Soft; // it's now signaled to stop 113 lane_->cancel_request = CancelRequest::Soft; // it's now signaled to stop
114 // negative timeout: we don't want to truly abort the lane, we just want it to react to cancel_test() on its own 114 // negative timeout: we don't want to truly abort the lane, we just want it to react to cancel_test() on its own
@@ -126,7 +126,7 @@ static CancelResult thread_cancel_soft(Lane* lane_, lua_Duration duration_, bool
126 126
127// ################################################################################################ 127// ################################################################################################
128 128
129static CancelResult thread_cancel_hard(Lane* lane_, lua_Duration duration_, bool wake_lane_) 129[[nodiscard]] static CancelResult thread_cancel_hard(Lane* lane_, lua_Duration duration_, bool wake_lane_)
130{ 130{
131 lane_->cancel_request = CancelRequest::Hard; // it's now signaled to stop 131 lane_->cancel_request = CancelRequest::Hard; // it's now signaled to stop
132 //lane_->m_thread.get_stop_source().request_stop(); 132 //lane_->m_thread.get_stop_source().request_stop();
@@ -204,7 +204,7 @@ CancelOp which_cancel_op(char const* op_string_)
204 204
205// ################################################################################################ 205// ################################################################################################
206 206
207static CancelOp which_cancel_op(lua_State* L, int idx_) 207[[nodiscard]] static CancelOp which_cancel_op(lua_State* L, int idx_)
208{ 208{
209 if (lua_type(L, idx_) == LUA_TSTRING) 209 if (lua_type(L, idx_) == LUA_TSTRING)
210 { 210 {
@@ -273,7 +273,7 @@ LUAG_FUNC(thread_cancel)
273 273
274 case CancelResult::Cancelled: 274 case CancelResult::Cancelled:
275 lua_pushboolean(L, 1); 275 lua_pushboolean(L, 1);
276 push_thread_status(L, lane); 276 std::ignore = push_thread_status(L, lane);
277 break; 277 break;
278 } 278 }
279 // should never happen, only here to prevent the compiler from complaining of "not all control paths returning a value" 279 // should never happen, only here to prevent the compiler from complaining of "not all control paths returning a value"
diff --git a/src/cancel.h b/src/cancel.h
index 954b04e..060edb3 100644
--- a/src/cancel.h
+++ b/src/cancel.h
@@ -49,8 +49,8 @@ enum class CancelOp
49// crc64/we of string "CANCEL_ERROR" generated at http://www.nitrxgen.net/hashgen/ 49// crc64/we of string "CANCEL_ERROR" generated at http://www.nitrxgen.net/hashgen/
50static constexpr UniqueKey CANCEL_ERROR{ 0xe97d41626cc97577ull }; // 'raise_cancel_error' sentinel 50static constexpr UniqueKey CANCEL_ERROR{ 0xe97d41626cc97577ull }; // 'raise_cancel_error' sentinel
51 51
52CancelOp which_cancel_op(char const* op_string_); 52[[nodiscard]] CancelOp which_cancel_op(char const* op_string_);
53CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hook_count_, lua_Duration secs_, bool wake_lindas_); 53[[nodiscard]] CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hook_count_, lua_Duration secs_, bool wake_lindas_);
54 54
55[[noreturn]] static inline void raise_cancel_error(lua_State* L) 55[[noreturn]] static inline void raise_cancel_error(lua_State* L)
56{ 56{
diff --git a/src/compat.cpp b/src/compat.cpp
index 8acab25..9807390 100644
--- a/src/compat.cpp
+++ b/src/compat.cpp
@@ -15,7 +15,7 @@
15// ################################################################################################ 15// ################################################################################################
16// ################################################################################################ 16// ################################################################################################
17 17
18static int luaL_getsubtable (lua_State *L, int idx, const char *fname) 18[[nodiscard]] static int luaL_getsubtable(lua_State* L, int idx, const char* fname)
19{ 19{
20 lua_getfield(L, idx, fname); 20 lua_getfield(L, idx, fname);
21 if (lua_istable(L, -1)) 21 if (lua_istable(L, -1))
@@ -33,12 +33,12 @@ static int luaL_getsubtable (lua_State *L, int idx, const char *fname)
33 33
34// ################################################################################################ 34// ################################################################################################
35 35
36void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb) 36void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb)
37{ 37{
38 lua_pushcfunction(L, openf); 38 lua_pushcfunction(L, openf);
39 lua_pushstring(L, modname); /* argument to open function */ 39 lua_pushstring(L, modname); /* argument to open function */
40 lua_call(L, 1, 1); /* open module */ 40 lua_call(L, 1, 1); /* open module */
41 luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); 41 std::ignore = luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
42 lua_pushvalue(L, -2); /* make copy of module (call result) */ 42 lua_pushvalue(L, -2); /* make copy of module (call result) */
43 lua_setfield(L, -2, modname); /* _LOADED[modname] = module */ 43 lua_setfield(L, -2, modname); /* _LOADED[modname] = module */
44 lua_pop(L, 1); /* remove _LOADED table */ 44 lua_pop(L, 1); /* remove _LOADED table */
diff --git a/src/deep.cpp b/src/deep.cpp
index 55063b3..a3806aa 100644
--- a/src/deep.cpp
+++ b/src/deep.cpp
@@ -107,7 +107,7 @@ static void get_deep_lookup(lua_State* L)
107* Return the registered ID function for 'index' (deep userdata proxy), 107* Return the registered ID function for 'index' (deep userdata proxy),
108* or nullptr if 'index' is not a deep userdata proxy. 108* or nullptr if 'index' is not a deep userdata proxy.
109*/ 109*/
110static inline luaG_IdFunction get_idfunc(lua_State* L, int index, LookupMode mode_) 110[[nodiscard]] static inline luaG_IdFunction get_idfunc(lua_State* L, int index, LookupMode mode_)
111{ 111{
112 // when looking inside a keeper, we are 100% sure the object is a deep userdata 112 // when looking inside a keeper, we are 100% sure the object is a deep userdata
113 if (mode_ == LookupMode::FromKeeper) 113 if (mode_ == LookupMode::FromKeeper)
@@ -160,7 +160,7 @@ void free_deep_prelude(lua_State* L, DeepPrelude* prelude_)
160 * End of life for a proxy object; reduce the deep reference count and clean it up if reaches 0. 160 * End of life for a proxy object; reduce the deep reference count and clean it up if reaches 0.
161 * 161 *
162 */ 162 */
163static int deep_userdata_gc(lua_State* L) 163[[nodiscard]] static int deep_userdata_gc(lua_State* L)
164{ 164{
165 DeepPrelude** const proxy{ lua_tofulluserdata<DeepPrelude*>(L, 1) }; 165 DeepPrelude** const proxy{ lua_tofulluserdata<DeepPrelude*>(L, 1) };
166 DeepPrelude* p = *proxy; 166 DeepPrelude* p = *proxy;
@@ -470,10 +470,14 @@ bool copydeep(Universe* U, Dest L2, int L2_cache_i, Source L, int i, LookupMode
470 int const clone_i = lua_gettop( L2); 470 int const clone_i = lua_gettop( L2);
471 while( nuv) 471 while( nuv)
472 { 472 {
473 inter_copy_one( U, L2, L2_cache_i, L, lua_absindex( L, -1), VT::NORMAL, mode_, upName_); // u uv 473 std::ignore = inter_copy_one(U
474 , L2, L2_cache_i
475 , L, lua_absindex( L, -1)
476 , VT::NORMAL, mode_, upName_
477 ); // u uv
474 lua_pop( L, 1); // ... u [uv]* 478 lua_pop( L, 1); // ... u [uv]*
475 // this pops the value from the stack 479 // this pops the value from the stack
476 lua_setiuservalue( L2, clone_i, nuv); // u 480 lua_setiuservalue(L2, clone_i, nuv); // u
477 -- nuv; 481 -- nuv;
478 } 482 }
479 } 483 }
diff --git a/src/deep.h b/src/deep.h
index 6cf33ec..7be5c5d 100644
--- a/src/deep.h
+++ b/src/deep.h
@@ -36,7 +36,7 @@ enum class DeepOp
36 Module, 36 Module,
37}; 37};
38 38
39using luaG_IdFunction = void*(*)( lua_State* L, DeepOp op_); 39using luaG_IdFunction = void*(*)(lua_State* L, DeepOp op_);
40 40
41// ################################################################################################ 41// ################################################################################################
42 42
@@ -54,8 +54,8 @@ struct DeepPrelude
54 std::atomic<int> m_refcount{ 0 }; 54 std::atomic<int> m_refcount{ 0 };
55}; 55};
56 56
57char const* push_deep_proxy(Dest L, DeepPrelude* prelude, int nuv_, LookupMode mode_); 57[[nodiscard]] char const* push_deep_proxy(Dest L, DeepPrelude* prelude, int nuv_, LookupMode mode_);
58void free_deep_prelude( lua_State* L, DeepPrelude* prelude_); 58void free_deep_prelude(lua_State* L, DeepPrelude* prelude_);
59 59
60LANES_API int luaG_newdeepuserdata(Dest L, luaG_IdFunction idfunc, int nuv_); 60LANES_API [[nodiscard]] int luaG_newdeepuserdata(Dest L, luaG_IdFunction idfunc, int nuv_);
61LANES_API DeepPrelude* luaG_todeep(lua_State* L, luaG_IdFunction idfunc, int index); 61LANES_API [[nodiscard]] DeepPrelude* luaG_todeep(lua_State* L, luaG_IdFunction idfunc, int index);
diff --git a/src/keeper.cpp b/src/keeper.cpp
index 9718bda..19fbd06 100644
--- a/src/keeper.cpp
+++ b/src/keeper.cpp
@@ -61,12 +61,12 @@ class keeper_fifo
61 int limit{ -1 }; 61 int limit{ -1 };
62 62
63 // a fifo full userdata has one uservalue, the table that holds the actual fifo contents 63 // a fifo full userdata has one uservalue, the table that holds the actual fifo contents
64 static void* operator new([[maybe_unused]] size_t size_, lua_State* L) noexcept { return lua_newuserdatauv<keeper_fifo>(L, 1); } 64 [[nodiscard]] static void* operator new([[maybe_unused]] size_t size_, lua_State* L) noexcept { return lua_newuserdatauv<keeper_fifo>(L, 1); }
65 // always embedded somewhere else or "in-place constructed" as a full userdata 65 // always embedded somewhere else or "in-place constructed" as a full userdata
66 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception 66 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception
67 static void operator delete([[maybe_unused]] void* p_, lua_State* L) { ASSERT_L(!"should never be called") }; 67 static void operator delete([[maybe_unused]] void* p_, lua_State* L) { ASSERT_L(!"should never be called") };
68 68
69 static keeper_fifo* getPtr(lua_State* L, int idx_) 69 [[nodiscard]] static keeper_fifo* getPtr(lua_State* L, int idx_)
70 { 70 {
71 return lua_tofulluserdata<keeper_fifo>(L, idx_); 71 return lua_tofulluserdata<keeper_fifo>(L, idx_);
72 } 72 }
@@ -77,7 +77,7 @@ static constexpr int CONTENTS_TABLE{ 1 };
77// ################################################################################################## 77// ##################################################################################################
78 78
79// replaces the fifo ud by its uservalue on the stack 79// replaces the fifo ud by its uservalue on the stack
80static keeper_fifo* prepare_fifo_access(lua_State* L, int idx_) 80[[nodiscard]] static keeper_fifo* prepare_fifo_access(lua_State* L, int idx_)
81{ 81{
82 keeper_fifo* const fifo{ keeper_fifo::getPtr(L, idx_) }; 82 keeper_fifo* const fifo{ keeper_fifo::getPtr(L, idx_) };
83 if (fifo != nullptr) 83 if (fifo != nullptr)
@@ -95,7 +95,7 @@ static keeper_fifo* prepare_fifo_access(lua_State* L, int idx_)
95 95
96// in: nothing 96// in: nothing
97// out: { first = 1, count = 0, limit = -1} 97// out: { first = 1, count = 0, limit = -1}
98static keeper_fifo* fifo_new(lua_State* L) 98[[nodiscard]] static keeper_fifo* fifo_new(lua_State* L)
99{ 99{
100 STACK_GROW(L, 2); 100 STACK_GROW(L, 2);
101 STACK_CHECK_START_REL(L, 0); 101 STACK_CHECK_START_REL(L, 0);
@@ -213,46 +213,46 @@ int keeper_push_linda_storage(Universe* U, Dest L, void* ptr_, uintptr_t magic_)
213 Source const KL{ K ? K->L : nullptr }; 213 Source const KL{ K ? K->L : nullptr };
214 if (KL == nullptr) 214 if (KL == nullptr)
215 return 0; 215 return 0;
216 STACK_GROW(KL, 4); 216 STACK_GROW(KL, 4); // KEEPER MAIN
217 STACK_CHECK_START_REL(KL, 0); 217 STACK_CHECK_START_REL(KL, 0);
218 FIFOS_KEY.pushValue(KL); // fifos 218 FIFOS_KEY.pushValue(KL); // fifos
219 lua_pushlightuserdata(KL, ptr_); // fifos ud 219 lua_pushlightuserdata(KL, ptr_); // fifos ud
220 lua_rawget(KL, -2); // fifos storage 220 lua_rawget(KL, -2); // fifos storage
221 lua_remove(KL, -2); // storage 221 lua_remove(KL, -2); // storage
222 if (!lua_istable(KL, -1)) 222 if (!lua_istable(KL, -1))
223 { 223 {
224 lua_pop(KL, 1); // 224 lua_pop(KL, 1); //
225 STACK_CHECK(KL, 0); 225 STACK_CHECK(KL, 0);
226 return 0; 226 return 0;
227 } 227 }
228 // move data from keeper to destination state KEEPER MAIN 228 // move data from keeper to destination state
229 lua_pushnil(KL); // storage nil 229 lua_pushnil(KL); // storage nil
230 STACK_GROW(L, 5); 230 STACK_GROW(L, 5);
231 STACK_CHECK_START_REL(L, 0); 231 STACK_CHECK_START_REL(L, 0);
232 lua_newtable(L); // out 232 lua_newtable(L); // out
233 while (lua_next(KL, -2)) // storage key fifo 233 while (lua_next(KL, -2)) // storage key fifo
234 { 234 {
235 keeper_fifo* fifo = prepare_fifo_access(KL, -1); // storage key fifotbl 235 keeper_fifo* fifo = prepare_fifo_access(KL, -1); // storage key fifotbl
236 lua_pushvalue(KL, -2); // storage key fifotbl key 236 lua_pushvalue(KL, -2); // storage key fifotbl key
237 luaG_inter_move(U, KL, L, 1, LookupMode::FromKeeper); // storage key fifotbl // out key 237 std::ignore = luaG_inter_move(U, KL, L, 1, LookupMode::FromKeeper); // storage key fifotbl // out key
238 STACK_CHECK(L, 2); 238 STACK_CHECK(L, 2);
239 lua_newtable(L); // out key keyout 239 lua_newtable(L); // out key keyout
240 luaG_inter_move(U, KL, L, 1, LookupMode::FromKeeper); // storage key // out key keyout fifotbl 240 std::ignore = luaG_inter_move(U, KL, L, 1, LookupMode::FromKeeper); // storage key // out key keyout fifotbl
241 lua_pushinteger(L, fifo->first); // out key keyout fifotbl first 241 lua_pushinteger(L, fifo->first); // out key keyout fifotbl first
242 STACK_CHECK(L, 5); 242 STACK_CHECK(L, 5);
243 lua_setfield(L, -3, "first"); // out key keyout fifotbl 243 lua_setfield(L, -3, "first"); // out key keyout fifotbl
244 lua_pushinteger(L, fifo->count); // out key keyout fifobtl count 244 lua_pushinteger(L, fifo->count); // out key keyout fifobtl count
245 STACK_CHECK(L, 5); 245 STACK_CHECK(L, 5);
246 lua_setfield(L, -3, "count"); // out key keyout fifotbl 246 lua_setfield(L, -3, "count"); // out key keyout fifotbl
247 lua_pushinteger(L, fifo->limit); // out key keyout fifotbl limit 247 lua_pushinteger(L, fifo->limit); // out key keyout fifotbl limit
248 STACK_CHECK(L, 5); 248 STACK_CHECK(L, 5);
249 lua_setfield(L, -3, "limit"); // out key keyout fifotbl 249 lua_setfield(L, -3, "limit"); // out key keyout fifotbl
250 lua_setfield(L, -2, "fifo"); // out key keyout 250 lua_setfield(L, -2, "fifo"); // out key keyout
251 lua_rawset(L, -3); // out 251 lua_rawset(L, -3); // out
252 STACK_CHECK(L, 1); 252 STACK_CHECK(L, 1);
253 } 253 }
254 STACK_CHECK(L, 1); 254 STACK_CHECK(L, 1);
255 lua_pop(KL, 1); // 255 lua_pop(KL, 1); //
256 STACK_CHECK(KL, 0); 256 STACK_CHECK(KL, 0);
257 return 1; 257 return 1;
258} 258}
@@ -287,7 +287,7 @@ int keepercall_send(lua_State* L)
287 if( lua_isnil(L, -1)) 287 if( lua_isnil(L, -1))
288 { 288 {
289 lua_pop(L, 1); // ud key ... fifos 289 lua_pop(L, 1); // ud key ... fifos
290 fifo_new(L); // ud key ... fifos fifo 290 std::ignore = fifo_new(L); // ud key ... fifos fifo
291 lua_pushvalue(L, 2); // ud key ... fifos fifo key 291 lua_pushvalue(L, 2); // ud key ... fifos fifo key
292 lua_pushvalue(L, -2); // ud key ... fifos fifo key fifo 292 lua_pushvalue(L, -2); // ud key ... fifos fifo key fifo
293 lua_rawset(L, -4); // ud key ... fifos fifo 293 lua_rawset(L, -4); // ud key ... fifos fifo
@@ -465,7 +465,7 @@ int keepercall_set(lua_State* L)
465 { // fifos key [val [, ...]] nil 465 { // fifos key [val [, ...]] nil
466 // no need to wake writers in that case, because a writer can't wait on an inexistent key 466 // no need to wake writers in that case, because a writer can't wait on an inexistent key
467 lua_pop(L, 1); // fifos key [val [, ...]] 467 lua_pop(L, 1); // fifos key [val [, ...]]
468 fifo_new(L); // fifos key [val [, ...]] fifo 468 std::ignore = fifo_new(L); // fifos key [val [, ...]] fifo
469 lua_pushvalue(L, 2); // fifos key [val [, ...]] fifo key 469 lua_pushvalue(L, 2); // fifos key [val [, ...]] fifo key
470 lua_pushvalue(L, -2); // fifos key [val [, ...]] fifo key fifo 470 lua_pushvalue(L, -2); // fifos key [val [, ...]] fifo key fifo
471 lua_rawset(L, 1); // fifos key [val [, ...]] fifo 471 lua_rawset(L, 1); // fifos key [val [, ...]] fifo
diff --git a/src/keeper.h b/src/keeper.h
index 89fa2ab..627c7ea 100644
--- a/src/keeper.h
+++ b/src/keeper.h
@@ -38,23 +38,23 @@ static constexpr UniqueKey NIL_SENTINEL{ 0x7eaafa003a1d11a1ull };
38void init_keepers(Universe* U, lua_State* L); 38void init_keepers(Universe* U, lua_State* L);
39void close_keepers(Universe* U); 39void close_keepers(Universe* U);
40 40
41Keeper* which_keeper(Keepers* keepers_, uintptr_t magic_); 41[[nodiscard]] Keeper* which_keeper(Keepers* keepers_, uintptr_t magic_);
42Keeper* keeper_acquire(Keepers* keepers_, uintptr_t magic_); 42[[nodiscard]] Keeper* keeper_acquire(Keepers* keepers_, uintptr_t magic_);
43void keeper_release(Keeper* K_); 43void keeper_release(Keeper* K_);
44void keeper_toggle_nil_sentinels(lua_State* L, int val_i_, LookupMode const mode_); 44void keeper_toggle_nil_sentinels(lua_State* L, int val_i_, LookupMode const mode_);
45int keeper_push_linda_storage(Universe* U, Dest L, void* ptr_, uintptr_t magic_); 45[[nodiscard]] int keeper_push_linda_storage(Universe* U, Dest L, void* ptr_, uintptr_t magic_);
46 46
47using keeper_api_t = lua_CFunction; 47using keeper_api_t = lua_CFunction;
48#define KEEPER_API(_op) keepercall_##_op 48#define KEEPER_API(_op) keepercall_##_op
49#define PUSH_KEEPER_FUNC lua_pushcfunction 49#define PUSH_KEEPER_FUNC lua_pushcfunction
50// lua_Cfunctions to run inside a keeper state 50// lua_Cfunctions to run inside a keeper state
51int keepercall_clear(lua_State* L); 51[[nodiscard]] int keepercall_clear(lua_State* L);
52int keepercall_send(lua_State* L); 52[[nodiscard]] int keepercall_send(lua_State* L);
53int keepercall_receive(lua_State* L); 53[[nodiscard]] int keepercall_receive(lua_State* L);
54int keepercall_receive_batched(lua_State* L); 54[[nodiscard]] int keepercall_receive_batched(lua_State* L);
55int keepercall_limit(lua_State* L); 55[[nodiscard]] int keepercall_limit(lua_State* L);
56int keepercall_get(lua_State* L); 56[[nodiscard]] int keepercall_get(lua_State* L);
57int keepercall_set(lua_State* L); 57[[nodiscard]] int keepercall_set(lua_State* L);
58int keepercall_count(lua_State* L); 58[[nodiscard]] int keepercall_count(lua_State* L);
59 59
60int keeper_call(Universe* U, lua_State* K, keeper_api_t _func, lua_State* L, void* linda, int starting_index); 60[[nodiscard]] int keeper_call(Universe* U, lua_State* K, keeper_api_t _func, lua_State* L, void* linda, int starting_index);
diff --git a/src/lanes.cpp b/src/lanes.cpp
index 3d0c70d..2a5ebfd 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -162,7 +162,7 @@ static void securize_debug_threadname(lua_State* L, Lane* lane_)
162} 162}
163 163
164#if ERROR_FULL_STACK 164#if ERROR_FULL_STACK
165static int lane_error(lua_State* L); 165[[nodiscard]] static int lane_error(lua_State* L);
166// crc64/we of string "STACKTRACE_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 166// crc64/we of string "STACKTRACE_REGKEY" generated at http://www.nitrxgen.net/hashgen/
167static constexpr UniqueKey STACKTRACE_REGKEY{ 0x534af7d3226a429full }; 167static constexpr UniqueKey STACKTRACE_REGKEY{ 0x534af7d3226a429full };
168#endif // ERROR_FULL_STACK 168#endif // ERROR_FULL_STACK
@@ -188,7 +188,7 @@ static constexpr UniqueKey FINALIZER_REGKEY{ 0x188fccb8bf348e09ull };
188* Returns: true if a table was pushed 188* Returns: true if a table was pushed
189* false if no table found, not created, and nothing pushed 189* false if no table found, not created, and nothing pushed
190*/ 190*/
191static bool push_registry_table( lua_State* L, UniqueKey key, bool create) 191[[nodiscard]] static bool push_registry_table(lua_State* L, UniqueKey key, bool create)
192{ 192{
193 STACK_GROW(L, 3); 193 STACK_GROW(L, 3);
194 STACK_CHECK_START_REL(L, 0); 194 STACK_CHECK_START_REL(L, 0);
@@ -237,7 +237,7 @@ static void tracking_add(Lane* lane_)
237/* 237/*
238 * A free-running lane has ended; remove it from tracking chain 238 * A free-running lane has ended; remove it from tracking chain
239 */ 239 */
240static bool tracking_remove(Lane* lane_) 240[[nodiscard]] static bool tracking_remove(Lane* lane_)
241{ 241{
242 bool found{ false }; 242 bool found{ false };
243 std::lock_guard<std::mutex> guard{ lane_->U->tracking_cs }; 243 std::lock_guard<std::mutex> guard{ lane_->U->tracking_cs };
@@ -277,7 +277,7 @@ Lane::~Lane()
277 if (U->tracking_first != nullptr) 277 if (U->tracking_first != nullptr)
278 { 278 {
279 // Lane was cleaned up, no need to handle at process termination 279 // Lane was cleaned up, no need to handle at process termination
280 tracking_remove(this); 280 std::ignore = tracking_remove(this);
281 } 281 }
282#endif // HAVE_LANE_TRACKING() 282#endif // HAVE_LANE_TRACKING()
283} 283}
@@ -300,10 +300,10 @@ LUAG_FUNC( set_finalizer)
300{ 300{
301 luaL_argcheck(L, lua_isfunction(L, 1), 1, "finalizer should be a function"); 301 luaL_argcheck(L, lua_isfunction(L, 1), 1, "finalizer should be a function");
302 luaL_argcheck(L, lua_gettop( L) == 1, 1, "too many arguments"); 302 luaL_argcheck(L, lua_gettop( L) == 1, 1, "too many arguments");
303 // Get the current finalizer table (if any) 303 // Get the current finalizer table (if any), create one if it doesn't exist
304 push_registry_table(L, FINALIZER_REGKEY, true /*do create if none*/); // finalizer {finalisers} 304 std::ignore = push_registry_table(L, FINALIZER_REGKEY, true); // finalizer {finalisers}
305 STACK_GROW(L, 2); 305 STACK_GROW(L, 2);
306 lua_pushinteger(L, lua_rawlen(L, -1) + 1); // finalizer {finalisers} idx 306 lua_pushinteger(L, lua_rawlen(L, -1) + 1); // finalizer {finalisers} idx
307 lua_pushvalue(L, 1); // finalizer {finalisers} idx finalizer 307 lua_pushvalue(L, 1); // finalizer {finalisers} idx finalizer
308 lua_rawset(L, -3); // finalizer {finalisers} 308 lua_rawset(L, -3); // finalizer {finalisers}
309 lua_pop(L, 2); // 309 lua_pop(L, 2); //
@@ -326,7 +326,7 @@ LUAG_FUNC( set_finalizer)
326// 326//
327static void push_stack_trace( lua_State* L, int rc_, int stk_base_); 327static void push_stack_trace( lua_State* L, int rc_, int stk_base_);
328 328
329static int run_finalizers( lua_State* L, int lua_rc) 329[[nodiscard]] static int run_finalizers(lua_State* L, int lua_rc)
330{ 330{
331 int finalizers_index; 331 int finalizers_index;
332 int n; 332 int n;
@@ -430,7 +430,7 @@ static void selfdestruct_add(Lane* lane_)
430/* 430/*
431 * A free-running lane has ended; remove it from selfdestruct chain 431 * A free-running lane has ended; remove it from selfdestruct chain
432 */ 432 */
433static bool selfdestruct_remove(Lane* lane_) 433[[nodiscard]] static bool selfdestruct_remove(Lane* lane_)
434{ 434{
435 bool found{ false }; 435 bool found{ false };
436 std::lock_guard<std::mutex> guard{ lane_->U->selfdestruct_cs }; 436 std::lock_guard<std::mutex> guard{ lane_->U->selfdestruct_cs };
@@ -465,7 +465,7 @@ static bool selfdestruct_remove(Lane* lane_)
465/* 465/*
466* Process end; cancel any still free-running threads 466* Process end; cancel any still free-running threads
467*/ 467*/
468static int universe_gc( lua_State* L) 468[[nodiscard]] static int universe_gc(lua_State* L)
469{ 469{
470 Universe* const U{ lua_tofulluserdata<Universe>(L, 1) }; 470 Universe* const U{ lua_tofulluserdata<Universe>(L, 1) };
471 lua_Duration const shutdown_timeout{ lua_tonumber(L, lua_upvalueindex(1)) }; 471 lua_Duration const shutdown_timeout{ lua_tonumber(L, lua_upvalueindex(1)) };
@@ -638,7 +638,7 @@ LUAG_FUNC( set_error_reporting)
638 return 0; 638 return 0;
639} 639}
640 640
641static int lane_error(lua_State* L) 641[[nodiscard]] static int lane_error(lua_State* L)
642{ 642{
643 // error message (any type) 643 // error message (any type)
644 STACK_CHECK_START_ABS(L, 1); // some_error 644 STACK_CHECK_START_ABS(L, 1); // some_error
@@ -1176,7 +1176,10 @@ LUAG_FUNC(lane_new)
1176 if (lua_pcall( L2, 1, 1, 0) != LUA_OK) // ret/errcode 1176 if (lua_pcall( L2, 1, 1, 0) != LUA_OK) // ret/errcode
1177 { 1177 {
1178 // propagate error to main state if any 1178 // propagate error to main state if any
1179 luaG_inter_move(U, Source{ L2 }, Dest{ L }, 1, LookupMode::LaneBody); // func libs priority globals package required gc_cb [... args ...] n "modname" error 1179 std::ignore = luaG_inter_move(U
1180 , Source{ L2 }, Dest{ L }
1181 , 1, LookupMode::LaneBody
1182 ); // func libs priority globals package required gc_cb [... args ...] n "modname" error
1180 raise_lua_error(L); 1183 raise_lua_error(L);
1181 } 1184 }
1182 // after requiring the module, register the functions it exported in our name<->function database 1185 // after requiring the module, register the functions it exported in our name<->function database
@@ -1209,7 +1212,7 @@ LUAG_FUNC(lane_new)
1209 lua_pushglobaltable(L2); // _G 1212 lua_pushglobaltable(L2); // _G
1210 while( lua_next(L, globals_idx)) // func libs priority globals package required gc_cb [... args ...] k v 1213 while( lua_next(L, globals_idx)) // func libs priority globals package required gc_cb [... args ...] k v
1211 { 1214 {
1212 luaG_inter_copy(U, Source{ L }, Dest{ L2 }, 2, LookupMode::LaneBody); // _G k v 1215 std::ignore = luaG_inter_copy(U, Source{ L }, Dest{ L2 }, 2, LookupMode::LaneBody); // _G k v
1213 // assign it in L2's globals table 1216 // assign it in L2's globals table
1214 lua_rawset(L2, -3); // _G 1217 lua_rawset(L2, -3); // _G
1215 lua_pop(L, 1); // func libs priority globals package required gc_cb [... args ...] k 1218 lua_pop(L, 1); // func libs priority globals package required gc_cb [... args ...] k
@@ -1290,7 +1293,7 @@ LUAG_FUNC(lane_new)
1290// and the issue of canceling/killing threads at gc is not very nice, either 1293// and the issue of canceling/killing threads at gc is not very nice, either
1291// (would easily cause waits at gc cycle, which we don't want). 1294// (would easily cause waits at gc cycle, which we don't want).
1292// 1295//
1293static int lane_gc(lua_State* L) 1296[[nodiscard]] static int lane_gc(lua_State* L)
1294{ 1297{
1295 bool have_gc_cb{ false }; 1298 bool have_gc_cb{ false };
1296 Lane* const lane{ lua_toLane(L, 1) }; // ud 1299 Lane* const lane{ lua_toLane(L, 1) }; // ud
@@ -1356,7 +1359,7 @@ static int lane_gc(lua_State* L)
1356// / "error" finished at an error, error value is there 1359// / "error" finished at an error, error value is there
1357// / "cancelled" execution cancelled by M (state gone) 1360// / "cancelled" execution cancelled by M (state gone)
1358// 1361//
1359static char const * thread_status_string(Lane* lane_) 1362[[nodiscard]] static char const* thread_status_string(Lane* lane_)
1360{ 1363{
1361 Lane::Status const st{ lane_->m_status }; // read just once (volatile) 1364 Lane::Status const st{ lane_->m_status }; // read just once (volatile)
1362 char const* str = 1365 char const* str =
@@ -1624,20 +1627,20 @@ LUAG_FUNC(threads)
1624 { 1627 {
1625 Lane* lane{ U->tracking_first }; 1628 Lane* lane{ U->tracking_first };
1626 int index = 0; 1629 int index = 0;
1627 lua_newtable(L); // {} 1630 lua_newtable(L); // {}
1628 while (lane != TRACKING_END) 1631 while (lane != TRACKING_END)
1629 { 1632 {
1630 // insert a { name, status } tuple, so that several lanes with the same name can't clobber each other 1633 // insert a { name, status } tuple, so that several lanes with the same name can't clobber each other
1631 lua_newtable(L); // {} {} 1634 lua_newtable(L); // {} {}
1632 lua_pushstring(L, lane->debug_name); // {} {} "name" 1635 lua_pushstring(L, lane->debug_name); // {} {} "name"
1633 lua_setfield(L, -2, "name"); // {} {} 1636 lua_setfield(L, -2, "name"); // {} {}
1634 push_thread_status(L, lane); // {} {} "status" 1637 std::ignore = push_thread_status(L, lane); // {} {} "status"
1635 lua_setfield(L, -2, "status"); // {} {} 1638 lua_setfield(L, -2, "status"); // {} {}
1636 lua_rawseti(L, -2, ++index); // {} 1639 lua_rawseti(L, -2, ++index); // {}
1637 lane = lane->tracking_next; 1640 lane = lane->tracking_next;
1638 } 1641 }
1639 } 1642 }
1640 return lua_gettop(L) - top; // 0 or 1 1643 return lua_gettop(L) - top; // 0 or 1
1641} 1644}
1642#endif // HAVE_LANE_TRACKING() 1645#endif // HAVE_LANE_TRACKING()
1643 1646
@@ -1723,7 +1726,7 @@ LUAG_FUNC(wakeup_conv)
1723 */ 1726 */
1724 1727
1725extern int LG_linda(lua_State* L); 1728extern int LG_linda(lua_State* L);
1726static const struct luaL_Reg lanes_functions[] = 1729static struct luaL_Reg const lanes_functions[] =
1727{ 1730{
1728 { "linda", LG_linda }, 1731 { "linda", LG_linda },
1729 { "now_secs", LG_now_secs }, 1732 { "now_secs", LG_now_secs },
@@ -2022,9 +2025,9 @@ LANES_API int luaopen_lanes_core( lua_State* L)
2022 return 1; 2025 return 1;
2023} 2026}
2024 2027
2025static int default_luaopen_lanes( lua_State* L) 2028[[nodiscard]] static int default_luaopen_lanes(lua_State* L)
2026{ 2029{
2027 int rc = luaL_loadfile(L, "lanes.lua") || lua_pcall(L, 0, 1, 0); 2030 int const rc{ luaL_loadfile(L, "lanes.lua") || lua_pcall(L, 0, 1, 0) };
2028 if (rc != LUA_OK) 2031 if (rc != LUA_OK)
2029 { 2032 {
2030 return luaL_error(L, "failed to initialize embedded Lanes"); 2033 return luaL_error(L, "failed to initialize embedded Lanes");
diff --git a/src/lanes.h b/src/lanes.h
index 05a0a5c..bc8de55 100644
--- a/src/lanes.h
+++ b/src/lanes.h
@@ -20,7 +20,7 @@ extern "C" {
20#define LANES_VERSION_GREATER_THAN(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>PATCH)))) 20#define LANES_VERSION_GREATER_THAN(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>PATCH))))
21#define LANES_VERSION_GREATER_OR_EQUAL(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>=PATCH)))) 21#define LANES_VERSION_GREATER_OR_EQUAL(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>=PATCH))))
22 22
23LANES_API int luaopen_lanes_core(lua_State* L); 23LANES_API [[nodiscard]] int luaopen_lanes_core(lua_State* L);
24 24
25// Call this to work with embedded Lanes instead of calling luaopen_lanes_core() 25// Call this to work with embedded Lanes instead of calling luaopen_lanes_core()
26LANES_API void luaopen_lanes_embedded(lua_State* L, lua_CFunction _luaopen_lanes); 26LANES_API void luaopen_lanes_embedded(lua_State* L, lua_CFunction _luaopen_lanes);
diff --git a/src/lanes_private.h b/src/lanes_private.h
index 0fcbbfc..ba40e44 100644
--- a/src/lanes_private.h
+++ b/src/lanes_private.h
@@ -78,7 +78,7 @@ class Lane
78 // 78 //
79 // For tracking only 79 // For tracking only
80 80
81 static void* operator new(size_t size_, Universe* U_) noexcept { return U_->internal_allocator.alloc(size_); } 81 [[nodiscard]] static void* operator new(size_t size_, Universe* U_) noexcept { return U_->internal_allocator.alloc(size_); }
82 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception 82 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception
83 static void operator delete(void* p_, Universe* U_) { U_->internal_allocator.free(p_, sizeof(Lane)); } 83 static void operator delete(void* p_, Universe* U_) { U_->internal_allocator.free(p_, sizeof(Lane)); }
84 // this one is for us, to make sure memory is freed by the correct allocator 84 // this one is for us, to make sure memory is freed by the correct allocator
@@ -87,7 +87,7 @@ class Lane
87 Lane(Universe* U_, lua_State* L_); 87 Lane(Universe* U_, lua_State* L_);
88 ~Lane(); 88 ~Lane();
89 89
90 bool waitForCompletion(lua_Duration duration_); 90 [[nodiscard]] bool waitForCompletion(lua_Duration duration_);
91 void startThread(int priority_); 91 void startThread(int priority_);
92}; 92};
93 93
@@ -98,6 +98,9 @@ static constexpr UniqueKey LANE_POINTER_REGKEY{ 0xB3022205633743BCull }; // used
98// 'Lane' are malloc/free'd and the handle only carries a pointer. 98// 'Lane' are malloc/free'd and the handle only carries a pointer.
99// This is not deep userdata since the handle's not portable among lanes. 99// This is not deep userdata since the handle's not portable among lanes.
100// 100//
101#define lua_toLane(L, i) (*((Lane**) luaL_checkudata( L, i, "Lane"))) 101[[nodiscard]] inline Lane* lua_toLane(lua_State* L, int i_)
102{
103 return *(static_cast<Lane**>(luaL_checkudata(L, i_, "Lane")));
104}
102 105
103int push_thread_status(lua_State* L, Lane* s); 106[[nodiscard]] int push_thread_status(lua_State* L, Lane* s);
diff --git a/src/linda.cpp b/src/linda.cpp
index 39977bc..50964ad 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -70,7 +70,7 @@ class Linda : public DeepPrelude // Deep userdata MUST start with this header
70 public: 70 public:
71 71
72 // a fifo full userdata has one uservalue, the table that holds the actual fifo contents 72 // a fifo full userdata has one uservalue, the table that holds the actual fifo contents
73 static void* operator new(size_t size_, Universe* U_) noexcept { return U_->internal_allocator.alloc(size_); } 73 [[nodiscard]] static void* operator new(size_t size_, Universe* U_) noexcept { return U_->internal_allocator.alloc(size_); }
74 // always embedded somewhere else or "in-place constructed" as a full userdata 74 // always embedded somewhere else or "in-place constructed" as a full userdata
75 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception 75 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception
76 static void operator delete(void* p_, Universe* U_) { U_->internal_allocator.free(p_, sizeof(Linda)); } 76 static void operator delete(void* p_, Universe* U_) { U_->internal_allocator.free(p_, sizeof(Linda)); }
@@ -137,10 +137,10 @@ class Linda : public DeepPrelude // Deep userdata MUST start with this header
137 return nullptr; 137 return nullptr;
138 } 138 }
139}; 139};
140static void* linda_id( lua_State*, DeepOp); 140[[nodiscard]] static void* linda_id(lua_State*, DeepOp);
141 141
142template<bool OPT> 142template<bool OPT>
143static inline Linda* lua_toLinda(lua_State* L, int idx_) 143[[nodiscard]] static inline Linda* lua_toLinda(lua_State* L, int idx_)
144{ 144{
145 Linda* const linda{ static_cast<Linda*>(luaG_todeep(L, linda_id, idx_)) }; 145 Linda* const linda{ static_cast<Linda*>(luaG_todeep(L, linda_id, idx_)) };
146 if (!OPT) 146 if (!OPT)
@@ -742,7 +742,7 @@ LUAG_FUNC(linda_deep)
742*/ 742*/
743 743
744template <bool OPT> 744template <bool OPT>
745static int linda_tostring(lua_State* L, int idx_) 745[[nodiscard]] static int linda_tostring(lua_State* L, int idx_)
746{ 746{
747 Linda* const linda{ lua_toLinda<OPT>(L, idx_) }; 747 Linda* const linda{ lua_toLinda<OPT>(L, idx_) };
748 if (linda != nullptr) 748 if (linda != nullptr)
@@ -851,7 +851,7 @@ LUAG_FUNC(linda_towatch)
851* For any other strings, the ID function must not react at all. This allows 851* For any other strings, the ID function must not react at all. This allows
852* future extensions of the system. 852* future extensions of the system.
853*/ 853*/
854static void* linda_id( lua_State* L, DeepOp op_) 854[[nodiscard]] static void* linda_id(lua_State* L, DeepOp op_)
855{ 855{
856 switch( op_) 856 switch( op_)
857 { 857 {
@@ -907,7 +907,7 @@ static void* linda_id( lua_State* L, DeepOp op_)
907 // Clean associated structures in the keeper state. 907 // Clean associated structures in the keeper state.
908 Keeper* const K{ need_acquire_release ? keeper_acquire(linda->U->keepers, linda->hashSeed()) : myK }; 908 Keeper* const K{ need_acquire_release ? keeper_acquire(linda->U->keepers, linda->hashSeed()) : myK };
909 // hopefully this won't ever raise an error as we would jump to the closest pcall site while forgetting to release the keeper mutex... 909 // hopefully this won't ever raise an error as we would jump to the closest pcall site while forgetting to release the keeper mutex...
910 keeper_call(linda->U, K->L, KEEPER_API(clear), L, linda, 0); 910 std::ignore = keeper_call(linda->U, K->L, KEEPER_API(clear), L, linda, 0);
911 if (need_acquire_release) 911 if (need_acquire_release)
912 { 912 {
913 keeper_release(K); 913 keeper_release(K);
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h
index 47ce90c..31ae8bd 100644
--- a/src/macros_and_utils.h
+++ b/src/macros_and_utils.h
@@ -23,11 +23,13 @@ extern char const* debugspew_indent;
23#define INDENT_BEGIN "%.*s " 23#define INDENT_BEGIN "%.*s "
24#define INDENT_END , (U ? U->debugspew_indent_depth.load(std::memory_order_relaxed) : 0), debugspew_indent 24#define INDENT_END , (U ? U->debugspew_indent_depth.load(std::memory_order_relaxed) : 0), debugspew_indent
25#define DEBUGSPEW_CODE(_code) _code 25#define DEBUGSPEW_CODE(_code) _code
26#define DEBUGSPEW_PARAM_COMMA( param_) param_, 26#define DEBUGSPEW_OR_NOT(a_, b_) a_
27#define DEBUGSPEW_PARAM_COMMA(param_) param_,
27#define DEBUGSPEW_COMMA_PARAM( param_) , param_ 28#define DEBUGSPEW_COMMA_PARAM( param_) , param_
28#else // USE_DEBUG_SPEW() 29#else // USE_DEBUG_SPEW()
29#define DEBUGSPEW_CODE(_code) 30#define DEBUGSPEW_CODE(_code)
30#define DEBUGSPEW_PARAM_COMMA( param_) 31#define DEBUGSPEW_OR_NOT(a_, b_) b_
32#define DEBUGSPEW_PARAM_COMMA(param_)
31#define DEBUGSPEW_COMMA_PARAM( param_) 33#define DEBUGSPEW_COMMA_PARAM( param_)
32#endif // USE_DEBUG_SPEW() 34#endif // USE_DEBUG_SPEW()
33 35
@@ -130,20 +132,20 @@ inline void STACK_GROW(lua_State* L, int n_)
130 } 132 }
131} 133}
132 134
133#define LUAG_FUNC( func_name) int LG_##func_name( lua_State* L) 135#define LUAG_FUNC(func_name) [[nodiscard]] int LG_##func_name(lua_State* L)
134 136
135// ################################################################################################# 137// #################################################################################################
136 138
137// a small helper to extract a full userdata pointer from the stack in a safe way 139// a small helper to extract a full userdata pointer from the stack in a safe way
138template<typename T> 140template<typename T>
139T* lua_tofulluserdata(lua_State* L, int index_) 141[[nodiscard]] T* lua_tofulluserdata(lua_State* L, int index_)
140{ 142{
141 ASSERT_L(lua_isnil(L, index_) || lua_type(L, index_) == LUA_TUSERDATA); 143 ASSERT_L(lua_isnil(L, index_) || lua_type(L, index_) == LUA_TUSERDATA);
142 return static_cast<T*>(lua_touserdata(L, index_)); 144 return static_cast<T*>(lua_touserdata(L, index_));
143} 145}
144 146
145template<typename T> 147template<typename T>
146auto lua_tolightuserdata(lua_State* L, int index_) 148[[nodiscard]] auto lua_tolightuserdata(lua_State* L, int index_)
147{ 149{
148 ASSERT_L(lua_isnil(L, index_) || lua_islightuserdata(L, index_)); 150 ASSERT_L(lua_isnil(L, index_) || lua_islightuserdata(L, index_));
149 if constexpr (std::is_pointer_v<T>) 151 if constexpr (std::is_pointer_v<T>)
@@ -157,7 +159,7 @@ auto lua_tolightuserdata(lua_State* L, int index_)
157} 159}
158 160
159template <typename T> 161template <typename T>
160T* lua_newuserdatauv(lua_State* L, int nuvalue_) 162[[nodiscard]] T* lua_newuserdatauv(lua_State* L, int nuvalue_)
161{ 163{
162 return static_cast<T*>(lua_newuserdatauv(L, sizeof(T), nuvalue_)); 164 return static_cast<T*>(lua_newuserdatauv(L, sizeof(T), nuvalue_));
163} 165}
@@ -175,6 +177,7 @@ using lua_Duration = std::chrono::template duration<lua_Number>;
175 177
176// ################################################################################################# 178// #################################################################################################
177 179
180// A unique type generator
178template <typename T, auto = []{}> 181template <typename T, auto = []{}>
179struct Unique 182struct Unique
180{ 183{
diff --git a/src/state.cpp b/src/state.cpp
index 6a9ada7..496e21e 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -49,7 +49,7 @@ THE SOFTWARE.
49// 49//
50// Upvalues: [1]: original 'require' function 50// Upvalues: [1]: original 'require' function
51// 51//
52static int luaG_new_require( lua_State* L) 52[[nodiscard]] static int luaG_new_require(lua_State* L)
53{ 53{
54 int rc; 54 int rc;
55 int const args = lua_gettop( L); // args 55 int const args = lua_gettop( L); // args
@@ -110,7 +110,7 @@ void serialize_require(DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L)
110 110
111/*---=== luaG_newstate ===---*/ 111/*---=== luaG_newstate ===---*/
112 112
113static int require_lanes_core( lua_State* L) 113[[nodiscard]] static int require_lanes_core(lua_State* L)
114{ 114{
115 // leaves a copy of 'lanes.core' module table on the stack 115 // leaves a copy of 'lanes.core' module table on the stack
116 luaL_requiref( L, "lanes.core", luaopen_lanes_core, 0); 116 luaL_requiref( L, "lanes.core", luaopen_lanes_core, 0);
@@ -118,7 +118,7 @@ static int require_lanes_core( lua_State* L)
118} 118}
119 119
120 120
121static const luaL_Reg libs[] = 121static luaL_Reg const libs[] =
122{ 122{
123 { LUA_LOADLIBNAME, luaopen_package}, 123 { LUA_LOADLIBNAME, luaopen_package},
124 { LUA_TABLIBNAME, luaopen_table}, 124 { LUA_TABLIBNAME, luaopen_table},
diff --git a/src/state.h b/src/state.h
index 2601f77..e1c311a 100644
--- a/src/state.h
+++ b/src/state.h
@@ -10,8 +10,8 @@ void serialize_require(DEBUGSPEW_PARAM_COMMA(Universe* U) lua_State* L);
10 10
11// ################################################################################################ 11// ################################################################################################
12 12
13lua_State* create_state(Universe* U, lua_State* from_); 13[[nodiscard]] lua_State* create_state(Universe* U, lua_State* from_);
14lua_State* luaG_newstate(Universe* U, Source _from, char const* libs); 14[[nodiscard]] lua_State* luaG_newstate(Universe* U, Source _from, char const* libs);
15 15
16// ################################################################################################ 16// ################################################################################################
17 17
diff --git a/src/threading.cpp b/src/threading.cpp
index d278bb1..259693a 100644
--- a/src/threading.cpp
+++ b/src/threading.cpp
@@ -209,7 +209,7 @@ void THREAD_SETNAME(char const* _name)
209// general its implementation is pretty much trivial, as on Win32 target 209// general its implementation is pretty much trivial, as on Win32 target
210// just SCHED_OTHER can be supported. 210// just SCHED_OTHER can be supported.
211#undef pthread_attr_setschedpolicy 211#undef pthread_attr_setschedpolicy
212static int pthread_attr_setschedpolicy(pthread_attr_t* attr, int policy) 212[[nodiscard]] static int pthread_attr_setschedpolicy(pthread_attr_t* attr, int policy)
213{ 213{
214 if (policy != SCHED_OTHER) 214 if (policy != SCHED_OTHER)
215 { 215 {
@@ -348,7 +348,7 @@ static int const gs_prio_remap[] =
348#endif // _PRIO_0 348#endif // _PRIO_0
349}; 349};
350 350
351static int select_prio(int prio /* -3..+3 */) 351[[nodiscard]] static int select_prio(int prio /* -3..+3 */)
352{ 352{
353 if (prio == THREAD_PRIO_DEFAULT) 353 if (prio == THREAD_PRIO_DEFAULT)
354 prio = 0; 354 prio = 0;
diff --git a/src/threading_osx.h b/src/threading_osx.h
index b47d2f6..f4d41e0 100644
--- a/src/threading_osx.h
+++ b/src/threading_osx.h
@@ -2,8 +2,7 @@
2 * THREADING_OSX.H 2 * THREADING_OSX.H
3 * http://yyshen.github.io/2015/01/18/binding_threads_to_cores_osx.html 3 * http://yyshen.github.io/2015/01/18/binding_threads_to_cores_osx.html
4 */ 4 */
5#ifndef __threading_osx_h__ 5#pragma once
6#define __threading_osx_h__ 1
7 6
8#include <mach/mach_types.h> 7#include <mach/mach_types.h>
9#include <mach/thread_act.h> 8#include <mach/thread_act.h>
@@ -18,9 +17,9 @@ struct cpu_set_t
18 17
19static inline void CPU_ZERO(cpu_set_t *cs) { cs->count = 0; } 18static inline void CPU_ZERO(cpu_set_t *cs) { cs->count = 0; }
20static inline void CPU_SET(int num, cpu_set_t *cs) { cs->count |= (1 << num); } 19static inline void CPU_SET(int num, cpu_set_t *cs) { cs->count |= (1 << num); }
21static inline int CPU_ISSET(int num, cpu_set_t *cs) { return (cs->count & (1 << num)); } 20[[nodiscard]] static inline int CPU_ISSET(int num, cpu_set_t *cs) { return (cs->count & (1 << num)); }
22 21
23int sched_getaffinity(pid_t pid, size_t cpu_size, cpu_set_t *cpu_set) 22[[nodiscard]] int sched_getaffinity(pid_t pid, size_t cpu_size, cpu_set_t *cpu_set)
24{ 23{
25 int32_t core_count = 0; 24 int32_t core_count = 0;
26 size_t len = sizeof(core_count); 25 size_t len = sizeof(core_count);
@@ -39,7 +38,7 @@ int sched_getaffinity(pid_t pid, size_t cpu_size, cpu_set_t *cpu_set)
39 return 0; 38 return 0;
40} 39}
41 40
42int pthread_setaffinity_np(pthread_t thread, size_t cpu_size, cpu_set_t *cpu_set) 41[[nodiscard]] int pthread_setaffinity_np(pthread_t thread, size_t cpu_size, cpu_set_t *cpu_set)
43{ 42{
44 thread_port_t mach_thread; 43 thread_port_t mach_thread;
45 int core = 0; 44 int core = 0;
@@ -57,4 +56,3 @@ int pthread_setaffinity_np(pthread_t thread, size_t cpu_size, cpu_set_t *cpu_set
57 return 0; 56 return 0;
58} 57}
59 58
60#endif
diff --git a/src/tools.cpp b/src/tools.cpp
index 07f9ae6..4083a57 100644
--- a/src/tools.cpp
+++ b/src/tools.cpp
@@ -144,7 +144,7 @@ void luaG_dump( lua_State* L)
144// ################################################################################################ 144// ################################################################################################
145 145
146// same as PUC-Lua l_alloc 146// same as PUC-Lua l_alloc
147extern "C" static void* libc_lua_Alloc([[maybe_unused]] void* ud, [[maybe_unused]] void* ptr_, [[maybe_unused]] size_t osize_, size_t nsize_) 147extern "C" [[nodiscard]] static void* libc_lua_Alloc([[maybe_unused]] void* ud, [[maybe_unused]] void* ptr_, [[maybe_unused]] size_t osize_, size_t nsize_)
148{ 148{
149 if (nsize_ == 0) 149 if (nsize_ == 0)
150 { 150 {
@@ -159,7 +159,7 @@ extern "C" static void* libc_lua_Alloc([[maybe_unused]] void* ud, [[maybe_unused
159 159
160// ################################################################################################# 160// #################################################################################################
161 161
162static int luaG_provide_protected_allocator(lua_State* L) 162[[nodiscard]] static int luaG_provide_protected_allocator(lua_State* L)
163{ 163{
164 Universe* const U{ universe_get(L) }; 164 Universe* const U{ universe_get(L) };
165 // push a new full userdata on the stack, giving access to the universe's protected allocator 165 // push a new full userdata on the stack, giving access to the universe's protected allocator
@@ -234,7 +234,7 @@ void initialize_allocator_function(Universe* U, lua_State* L)
234 234
235// ################################################################################################ 235// ################################################################################################
236 236
237static int dummy_writer( lua_State* L, void const* p, size_t sz, void* ud) 237[[nodiscard]] static int dummy_writer(lua_State* L, void const* p, size_t sz, void* ud)
238{ 238{
239 (void)L; (void)p; (void)sz; (void) ud; // unused 239 (void)L; (void)p; (void)sz; (void) ud; // unused
240 return 666; 240 return 666;
@@ -291,7 +291,7 @@ FuncSubType luaG_getfuncsubtype( lua_State *L, int _i)
291 291
292// ################################################################################################# 292// #################################################################################################
293 293
294static lua_CFunction luaG_tocfunction(lua_State* L, int _i, FuncSubType* _out) 294[[nodiscard]] static lua_CFunction luaG_tocfunction(lua_State* L, int _i, FuncSubType* _out)
295{ 295{
296 lua_CFunction p = lua_tocfunction( L, _i); 296 lua_CFunction p = lua_tocfunction( L, _i);
297 *_out = luaG_getfuncsubtype( L, _i); 297 *_out = luaG_getfuncsubtype( L, _i);
@@ -304,7 +304,7 @@ static constexpr UniqueKey LOOKUPCACHE_REGKEY{ 0x837a68dfc6fcb716ull };
304// ################################################################################################# 304// #################################################################################################
305 305
306// inspired from tconcat() in ltablib.c 306// inspired from tconcat() in ltablib.c
307static char const* luaG_pushFQN( lua_State* L, int t, int last, size_t* length) 307[[nodiscard]] static char const* luaG_pushFQN(lua_State* L, int t, int last, size_t* length)
308{ 308{
309 int i = 1; 309 int i = 1;
310 luaL_Buffer b; 310 luaL_Buffer b;
@@ -338,7 +338,7 @@ static char const* luaG_pushFQN( lua_State* L, int t, int last, size_t* length)
338 * if we already had an entry of type [o] = ..., replace the name if the new one is shorter 338 * if we already had an entry of type [o] = ..., replace the name if the new one is shorter
339 * pops the processed object from the stack 339 * pops the processed object from the stack
340 */ 340 */
341static void update_lookup_entry( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, int _ctx_base, int _depth) 341static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, int _ctx_base, int _depth)
342{ 342{
343 // slot 1 in the stack contains the table that receives everything we found 343 // slot 1 in the stack contains the table that receives everything we found
344 int const dest = _ctx_base; 344 int const dest = _ctx_base;
@@ -362,7 +362,7 @@ static void update_lookup_entry( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State*
362 ++ _depth; 362 ++ _depth;
363 lua_rawseti( L, fqn, _depth); // ... {bfc} k o name? 363 lua_rawseti( L, fqn, _depth); // ... {bfc} k o name?
364 // generate name 364 // generate name
365 DEBUGSPEW_CODE( newName =) luaG_pushFQN( L, fqn, _depth, &newNameLength); // ... {bfc} k o name? "f.q.n" 365 DEBUGSPEW_OR_NOT(newName, std::ignore) = luaG_pushFQN(L, fqn, _depth, &newNameLength);// ... {bfc} k o name? "f.q.n"
366 // Lua 5.2 introduced a hash randomizer seed which causes table iteration to yield a different key order 366 // Lua 5.2 introduced a hash randomizer seed which causes table iteration to yield a different key order
367 // on different VMs even when the tables are populated the exact same way. 367 // on different VMs even when the tables are populated the exact same way.
368 // When Lua is built with compatibility options (such as LUA_COMPAT_ALL), 368 // When Lua is built with compatibility options (such as LUA_COMPAT_ALL),
@@ -613,7 +613,7 @@ static constexpr UniqueKey REG_MTID{ 0x2e68f9b4751584dcull };
613/* 613/*
614* Get a unique ID for metatable at [i]. 614* Get a unique ID for metatable at [i].
615*/ 615*/
616static lua_Integer get_mt_id( Universe* U, lua_State* L, int i) 616[[nodiscard]] static lua_Integer get_mt_id(Universe* U, lua_State* L, int i)
617{ 617{
618 lua_Integer id; 618 lua_Integer id;
619 619
@@ -654,25 +654,25 @@ static lua_Integer get_mt_id( Universe* U, lua_State* L, int i)
654// ################################################################################################# 654// #################################################################################################
655 655
656// function sentinel used to transfer native functions from/to keeper states 656// function sentinel used to transfer native functions from/to keeper states
657static int func_lookup_sentinel( lua_State* L) 657[[nodiscard]] static int func_lookup_sentinel(lua_State* L)
658{ 658{
659 return luaL_error( L, "function lookup sentinel for %s, should never be called", lua_tostring( L, lua_upvalueindex( 1))); 659 return luaL_error(L, "function lookup sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1)));
660} 660}
661 661
662// ################################################################################################# 662// #################################################################################################
663 663
664// function sentinel used to transfer native table from/to keeper states 664// function sentinel used to transfer native table from/to keeper states
665static int table_lookup_sentinel( lua_State* L) 665[[nodiscard]] static int table_lookup_sentinel(lua_State* L)
666{ 666{
667 return luaL_error( L, "table lookup sentinel for %s, should never be called", lua_tostring( L, lua_upvalueindex( 1))); 667 return luaL_error(L, "table lookup sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1)));
668} 668}
669 669
670// ################################################################################################# 670// #################################################################################################
671 671
672// function sentinel used to transfer cloned full userdata from/to keeper states 672// function sentinel used to transfer cloned full userdata from/to keeper states
673static int userdata_clone_sentinel( lua_State* L) 673[[nodiscard]] static int userdata_clone_sentinel(lua_State* L)
674{ 674{
675 return luaL_error( L, "userdata clone sentinel for %s, should never be called", lua_tostring( L, lua_upvalueindex( 1))); 675 return luaL_error(L, "userdata clone sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1)));
676} 676}
677 677
678// ################################################################################################# 678// #################################################################################################
@@ -680,7 +680,7 @@ static int userdata_clone_sentinel( lua_State* L)
680/* 680/*
681 * retrieve the name of a function/table in the lookup database 681 * retrieve the name of a function/table in the lookup database
682 */ 682 */
683static char const* find_lookup_name(lua_State* L, int i, LookupMode mode_, char const* upName_, size_t* len_) 683[[nodiscard]] static char const* find_lookup_name(lua_State* L, int i, LookupMode mode_, char const* upName_, size_t* len_)
684{ 684{
685 DEBUGSPEW_CODE( Universe* const U = universe_get( L)); 685 DEBUGSPEW_CODE( Universe* const U = universe_get( L));
686 char const* fqn; 686 char const* fqn;
@@ -753,7 +753,7 @@ static char const* find_lookup_name(lua_State* L, int i, LookupMode mode_, char
753/* 753/*
754 * Push a looked-up table, or nothing if we found nothing 754 * Push a looked-up table, or nothing if we found nothing
755 */ 755 */
756static bool lookup_table(Dest L2, Source L, int i, LookupMode mode_, char const* upName_) 756[[nodiscard]] static bool lookup_table(Dest L2, Source L, int i, LookupMode mode_, char const* upName_)
757{ 757{
758 // get the name of the table we want to send 758 // get the name of the table we want to send
759 size_t len; 759 size_t len;
@@ -830,13 +830,12 @@ static bool lookup_table(Dest L2, Source L, int i, LookupMode mode_, char const*
830 * Returns true if the table was cached (no need to fill it!); false if 830 * Returns true if the table was cached (no need to fill it!); false if
831 * it's a virgin. 831 * it's a virgin.
832 */ 832 */
833static bool push_cached_table(lua_State* L2, int L2_cache_i, lua_State* L, int i) 833[[nodiscard]] static bool push_cached_table(Dest L2, int L2_cache_i, Source L, int i)
834{ 834{
835 bool not_found_in_cache; // L2
836 void const* p{ lua_topointer(L, i) }; 835 void const* p{ lua_topointer(L, i) };
837 836
838 ASSERT_L( L2_cache_i != 0); 837 ASSERT_L( L2_cache_i != 0);
839 STACK_GROW( L2, 3); 838 STACK_GROW( L2, 3); // L2
840 STACK_CHECK_START_REL(L2, 0); 839 STACK_CHECK_START_REL(L2, 0);
841 840
842 // We don't need to use the from state ('L') in ID since the life span 841 // We don't need to use the from state ('L') in ID since the life span
@@ -847,7 +846,7 @@ static bool push_cached_table(lua_State* L2, int L2_cache_i, lua_State* L, int i
847 //fprintf( stderr, "<< ID: %s >>\n", lua_tostring( L2, -1)); 846 //fprintf( stderr, "<< ID: %s >>\n", lua_tostring( L2, -1));
848 847
849 lua_rawget( L2, L2_cache_i); // ... {cached|nil} 848 lua_rawget( L2, L2_cache_i); // ... {cached|nil}
850 not_found_in_cache = lua_isnil( L2, -1); 849 bool const not_found_in_cache{ lua_isnil(L2, -1) };
851 if( not_found_in_cache) 850 if( not_found_in_cache)
852 { 851 {
853 lua_pop( L2, 1); // ... 852 lua_pop( L2, 1); // ...
@@ -866,83 +865,83 @@ static bool push_cached_table(lua_State* L2, int L2_cache_i, lua_State* L, int i
866/* 865/*
867 * Return some name helping to identify an object 866 * Return some name helping to identify an object
868 */ 867 */
869static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) 868[[nodiscard]] static int discover_object_name_recur(lua_State* L, int shortest_, int depth_)
870{ 869{
871 int const what = 1; // o "r" {c} {fqn} ... {?} 870 int const what = 1; // o "r" {c} {fqn} ... {?}
872 int const result = 2; 871 int const result = 2;
873 int const cache = 3; 872 int const cache = 3;
874 int const fqn = 4; 873 int const fqn = 4;
875 // no need to scan this table if the name we will discover is longer than one we already know 874 // no need to scan this table if the name we will discover is longer than one we already know
876 if( shortest_ <= depth_ + 1) 875 if (shortest_ <= depth_ + 1)
877 { 876 {
878 return shortest_; 877 return shortest_;
879 } 878 }
880 STACK_GROW( L, 3); 879 STACK_GROW(L, 3);
881 STACK_CHECK_START_REL(L, 0); 880 STACK_CHECK_START_REL(L, 0);
882 // stack top contains the table to search in 881 // stack top contains the table to search in
883 lua_pushvalue( L, -1); // o "r" {c} {fqn} ... {?} {?} 882 lua_pushvalue(L, -1); // o "r" {c} {fqn} ... {?} {?}
884 lua_rawget( L, cache); // o "r" {c} {fqn} ... {?} nil/1 883 lua_rawget(L, cache); // o "r" {c} {fqn} ... {?} nil/1
885 // if table is already visited, we are done 884 // if table is already visited, we are done
886 if( !lua_isnil( L, -1)) 885 if( !lua_isnil(L, -1))
887 { 886 {
888 lua_pop( L, 1); // o "r" {c} {fqn} ... {?} 887 lua_pop(L, 1); // o "r" {c} {fqn} ... {?}
889 return shortest_; 888 return shortest_;
890 } 889 }
891 // examined table is not in the cache, add it now 890 // examined table is not in the cache, add it now
892 lua_pop( L, 1); // o "r" {c} {fqn} ... {?} 891 lua_pop(L, 1); // o "r" {c} {fqn} ... {?}
893 lua_pushvalue( L, -1); // o "r" {c} {fqn} ... {?} {?} 892 lua_pushvalue(L, -1); // o "r" {c} {fqn} ... {?} {?}
894 lua_pushinteger( L, 1); // o "r" {c} {fqn} ... {?} {?} 1 893 lua_pushinteger(L, 1); // o "r" {c} {fqn} ... {?} {?} 1
895 lua_rawset( L, cache); // o "r" {c} {fqn} ... {?} 894 lua_rawset(L, cache); // o "r" {c} {fqn} ... {?}
896 // scan table contents 895 // scan table contents
897 lua_pushnil( L); // o "r" {c} {fqn} ... {?} nil 896 lua_pushnil(L); // o "r" {c} {fqn} ... {?} nil
898 while( lua_next( L, -2)) // o "r" {c} {fqn} ... {?} k v 897 while (lua_next(L, -2)) // o "r" {c} {fqn} ... {?} k v
899 { 898 {
900 //char const *const strKey = (lua_type( L, -2) == LUA_TSTRING) ? lua_tostring( L, -2) : nullptr; // only for debugging 899 //char const *const strKey = (lua_type(L, -2) == LUA_TSTRING) ? lua_tostring(L, -2) : nullptr; // only for debugging
901 //lua_Number const numKey = (lua_type( L, -2) == LUA_TNUMBER) ? lua_tonumber( L, -2) : -6666; // only for debugging 900 //lua_Number const numKey = (lua_type(L, -2) == LUA_TNUMBER) ? lua_tonumber(L, -2) : -6666; // only for debugging
902 STACK_CHECK( L, 2); 901 STACK_CHECK(L, 2);
903 // append key name to fqn stack 902 // append key name to fqn stack
904 ++ depth_; 903 ++ depth_;
905 lua_pushvalue( L, -2); // o "r" {c} {fqn} ... {?} k v k 904 lua_pushvalue(L, -2); // o "r" {c} {fqn} ... {?} k v k
906 lua_rawseti( L, fqn, depth_); // o "r" {c} {fqn} ... {?} k v 905 lua_rawseti(L, fqn, depth_); // o "r" {c} {fqn} ... {?} k v
907 if( lua_rawequal( L, -1, what)) // is it what we are looking for? 906 if (lua_rawequal(L, -1, what)) // is it what we are looking for?
908 { 907 {
909 STACK_CHECK( L, 2); 908 STACK_CHECK(L, 2);
910 // update shortest name 909 // update shortest name
911 if( depth_ < shortest_) 910 if( depth_ < shortest_)
912 { 911 {
913 shortest_ = depth_; 912 shortest_ = depth_;
914 luaG_pushFQN( L, fqn, depth_, nullptr); // o "r" {c} {fqn} ... {?} k v "fqn" 913 std::ignore = luaG_pushFQN(L, fqn, depth_, nullptr); // o "r" {c} {fqn} ... {?} k v "fqn"
915 lua_replace( L, result); // o "r" {c} {fqn} ... {?} k v 914 lua_replace(L, result); // o "r" {c} {fqn} ... {?} k v
916 } 915 }
917 // no need to search further at this level 916 // no need to search further at this level
918 lua_pop( L, 2); // o "r" {c} {fqn} ... {?} 917 lua_pop(L, 2); // o "r" {c} {fqn} ... {?}
919 STACK_CHECK( L, 0); 918 STACK_CHECK(L, 0);
920 break; 919 break;
921 } 920 }
922 switch( lua_type( L, -1)) // o "r" {c} {fqn} ... {?} k v 921 switch (lua_type(L, -1)) // o "r" {c} {fqn} ... {?} k v
923 { 922 {
924 default: // nil, boolean, light userdata, number and string aren't identifiable 923 default: // nil, boolean, light userdata, number and string aren't identifiable
925 break; 924 break;
926 925
927 case LUA_TTABLE: // o "r" {c} {fqn} ... {?} k {} 926 case LUA_TTABLE: // o "r" {c} {fqn} ... {?} k {}
928 STACK_CHECK( L, 2); 927 STACK_CHECK(L, 2);
929 shortest_ = discover_object_name_recur( L, shortest_, depth_); 928 shortest_ = discover_object_name_recur(L, shortest_, depth_);
930 // search in the table's metatable too 929 // search in the table's metatable too
931 if( lua_getmetatable( L, -1)) // o "r" {c} {fqn} ... {?} k {} {mt} 930 if (lua_getmetatable(L, -1)) // o "r" {c} {fqn} ... {?} k {} {mt}
932 { 931 {
933 if( lua_istable( L, -1)) 932 if( lua_istable(L, -1))
934 { 933 {
935 ++ depth_; 934 ++ depth_;
936 lua_pushliteral( L, "__metatable"); // o "r" {c} {fqn} ... {?} k {} {mt} "__metatable" 935 lua_pushliteral(L, "__metatable"); // o "r" {c} {fqn} ... {?} k {} {mt} "__metatable"
937 lua_rawseti( L, fqn, depth_); // o "r" {c} {fqn} ... {?} k {} {mt} 936 lua_rawseti(L, fqn, depth_); // o "r" {c} {fqn} ... {?} k {} {mt}
938 shortest_ = discover_object_name_recur( L, shortest_, depth_); 937 shortest_ = discover_object_name_recur(L, shortest_, depth_);
939 lua_pushnil( L); // o "r" {c} {fqn} ... {?} k {} {mt} nil 938 lua_pushnil(L); // o "r" {c} {fqn} ... {?} k {} {mt} nil
940 lua_rawseti( L, fqn, depth_); // o "r" {c} {fqn} ... {?} k {} {mt} 939 lua_rawseti(L, fqn, depth_); // o "r" {c} {fqn} ... {?} k {} {mt}
941 -- depth_; 940 -- depth_;
942 } 941 }
943 lua_pop( L, 1); // o "r" {c} {fqn} ... {?} k {} 942 lua_pop(L, 1); // o "r" {c} {fqn} ... {?} k {}
944 } 943 }
945 STACK_CHECK( L, 2); 944 STACK_CHECK(L, 2);
946 break; 945 break;
947 946
948 case LUA_TTHREAD: // o "r" {c} {fqn} ... {?} k T 947 case LUA_TTHREAD: // o "r" {c} {fqn} ... {?} k T
@@ -950,61 +949,61 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_)
950 break; 949 break;
951 950
952 case LUA_TUSERDATA: // o "r" {c} {fqn} ... {?} k U 951 case LUA_TUSERDATA: // o "r" {c} {fqn} ... {?} k U
953 STACK_CHECK( L, 2); 952 STACK_CHECK(L, 2);
954 // search in the object's metatable (some modules are built that way) 953 // search in the object's metatable (some modules are built that way)
955 if( lua_getmetatable( L, -1)) // o "r" {c} {fqn} ... {?} k U {mt} 954 if (lua_getmetatable(L, -1)) // o "r" {c} {fqn} ... {?} k U {mt}
956 { 955 {
957 if( lua_istable( L, -1)) 956 if (lua_istable(L, -1))
958 { 957 {
959 ++ depth_; 958 ++ depth_;
960 lua_pushliteral( L, "__metatable"); // o "r" {c} {fqn} ... {?} k U {mt} "__metatable" 959 lua_pushliteral(L, "__metatable"); // o "r" {c} {fqn} ... {?} k U {mt} "__metatable"
961 lua_rawseti( L, fqn, depth_); // o "r" {c} {fqn} ... {?} k U {mt} 960 lua_rawseti(L, fqn, depth_); // o "r" {c} {fqn} ... {?} k U {mt}
962 shortest_ = discover_object_name_recur( L, shortest_, depth_); 961 shortest_ = discover_object_name_recur(L, shortest_, depth_);
963 lua_pushnil( L); // o "r" {c} {fqn} ... {?} k U {mt} nil 962 lua_pushnil(L); // o "r" {c} {fqn} ... {?} k U {mt} nil
964 lua_rawseti( L, fqn, depth_); // o "r" {c} {fqn} ... {?} k U {mt} 963 lua_rawseti(L, fqn, depth_); // o "r" {c} {fqn} ... {?} k U {mt}
965 -- depth_; 964 -- depth_;
966 } 965 }
967 lua_pop( L, 1); // o "r" {c} {fqn} ... {?} k U 966 lua_pop(L, 1); // o "r" {c} {fqn} ... {?} k U
968 } 967 }
969 STACK_CHECK( L, 2); 968 STACK_CHECK(L, 2);
970 // search in the object's uservalues 969 // search in the object's uservalues
971 { 970 {
972 int uvi = 1; 971 int uvi = 1;
973 while( lua_getiuservalue( L, -1, uvi) != LUA_TNONE) // o "r" {c} {fqn} ... {?} k U {u} 972 while (lua_getiuservalue(L, -1, uvi) != LUA_TNONE) // o "r" {c} {fqn} ... {?} k U {u}
974 { 973 {
975 if( lua_istable( L, -1)) // if it is a table, look inside 974 if( lua_istable(L, -1)) // if it is a table, look inside
976 { 975 {
977 ++ depth_; 976 ++ depth_;
978 lua_pushliteral( L, "uservalue"); // o "r" {c} {fqn} ... {?} k v {u} "uservalue" 977 lua_pushliteral(L, "uservalue"); // o "r" {c} {fqn} ... {?} k v {u} "uservalue"
979 lua_rawseti( L, fqn, depth_); // o "r" {c} {fqn} ... {?} k v {u} 978 lua_rawseti(L, fqn, depth_); // o "r" {c} {fqn} ... {?} k v {u}
980 shortest_ = discover_object_name_recur( L, shortest_, depth_); 979 shortest_ = discover_object_name_recur(L, shortest_, depth_);
981 lua_pushnil( L); // o "r" {c} {fqn} ... {?} k v {u} nil 980 lua_pushnil(L); // o "r" {c} {fqn} ... {?} k v {u} nil
982 lua_rawseti( L, fqn, depth_); // o "r" {c} {fqn} ... {?} k v {u} 981 lua_rawseti(L, fqn, depth_); // o "r" {c} {fqn} ... {?} k v {u}
983 -- depth_; 982 -- depth_;
984 } 983 }
985 lua_pop( L, 1); // o "r" {c} {fqn} ... {?} k U 984 lua_pop(L, 1); // o "r" {c} {fqn} ... {?} k U
986 ++ uvi; 985 ++ uvi;
987 } 986 }
988 // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now 987 // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now
989 lua_pop( L, 1); // o "r" {c} {fqn} ... {?} k U 988 lua_pop(L, 1); // o "r" {c} {fqn} ... {?} k U
990 } 989 }
991 STACK_CHECK( L, 2); 990 STACK_CHECK(L, 2);
992 break; 991 break;
993 } 992 }
994 // make ready for next iteration 993 // make ready for next iteration
995 lua_pop( L, 1); // o "r" {c} {fqn} ... {?} k 994 lua_pop(L, 1); // o "r" {c} {fqn} ... {?} k
996 // remove name from fqn stack 995 // remove name from fqn stack
997 lua_pushnil( L); // o "r" {c} {fqn} ... {?} k nil 996 lua_pushnil(L); // o "r" {c} {fqn} ... {?} k nil
998 lua_rawseti( L, fqn, depth_); // o "r" {c} {fqn} ... {?} k 997 lua_rawseti(L, fqn, depth_); // o "r" {c} {fqn} ... {?} k
999 STACK_CHECK( L, 1); 998 STACK_CHECK(L, 1);
1000 -- depth_; 999 -- depth_;
1001 } // o "r" {c} {fqn} ... {?} 1000 } // o "r" {c} {fqn} ... {?}
1002 STACK_CHECK( L, 0); 1001 STACK_CHECK(L, 0);
1003 // remove the visited table from the cache, in case a shorter path to the searched object exists 1002 // remove the visited table from the cache, in case a shorter path to the searched object exists
1004 lua_pushvalue( L, -1); // o "r" {c} {fqn} ... {?} {?} 1003 lua_pushvalue(L, -1); // o "r" {c} {fqn} ... {?} {?}
1005 lua_pushnil( L); // o "r" {c} {fqn} ... {?} {?} nil 1004 lua_pushnil(L); // o "r" {c} {fqn} ... {?} {?} nil
1006 lua_rawset( L, cache); // o "r" {c} {fqn} ... {?} 1005 lua_rawset(L, cache); // o "r" {c} {fqn} ... {?}
1007 STACK_CHECK( L, 0); 1006 STACK_CHECK(L, 0);
1008 return shortest_; 1007 return shortest_;
1009} 1008}
1010 1009
@@ -1169,7 +1168,7 @@ static char const* vt_names[] =
1169// we have to do it that way because we can't unbalance the stack between buffer operations 1168// we have to do it that way because we can't unbalance the stack between buffer operations
1170// namely, this means we can't push a function on top of the stack *after* we initialize the buffer! 1169// namely, this means we can't push a function on top of the stack *after* we initialize the buffer!
1171// luckily, this also works with earlier Lua versions 1170// luckily, this also works with earlier Lua versions
1172static int buf_writer( lua_State* L, void const* b, size_t size, void* ud) 1171[[nodiscard]] static int buf_writer(lua_State* L, void const* b, size_t size, void* ud)
1173{ 1172{
1174 luaL_Buffer* B = (luaL_Buffer*) ud; 1173 luaL_Buffer* B = (luaL_Buffer*) ud;
1175 if( !B->L) 1174 if( !B->L)
@@ -1339,7 +1338,7 @@ static void copy_func(Universe* U, Dest L2, int L2_cache_i, Source L, int i, Loo
1339static void copy_cached_func(Universe* U, Dest L2, int L2_cache_i, Source L, int i, LookupMode mode_, char const* upName_) 1338static void copy_cached_func(Universe* U, Dest L2, int L2_cache_i, Source L, int i, LookupMode mode_, char const* upName_)
1340{ 1339{
1341 FuncSubType funcSubType; 1340 FuncSubType funcSubType;
1342 /*lua_CFunction cfunc =*/ luaG_tocfunction( L, i, &funcSubType); // nullptr for LuaJIT-fast && bytecode functions 1341 std::ignore = luaG_tocfunction(L, i, &funcSubType); // nullptr for LuaJIT-fast && bytecode functions
1343 if( funcSubType == FST_Bytecode) 1342 if( funcSubType == FST_Bytecode)
1344 { 1343 {
1345 void* const aspointer = (void*)lua_topointer( L, i); 1344 void* const aspointer = (void*)lua_topointer( L, i);
@@ -1391,7 +1390,7 @@ static void copy_cached_func(Universe* U, Dest L2, int L2_cache_i, Source L, int
1391 1390
1392// ################################################################################################# 1391// #################################################################################################
1393 1392
1394static bool push_cached_metatable(Universe* U, Dest L2, int L2_cache_i, Source L, int i, LookupMode mode_, char const* upName_) 1393[[nodiscard]] static bool push_cached_metatable(Universe* U, Dest L2, int L2_cache_i, Source L, int i, LookupMode mode_, char const* upName_)
1395{ 1394{
1396 STACK_CHECK_START_REL(L, 0); 1395 STACK_CHECK_START_REL(L, 0);
1397 if( lua_getmetatable( L, i)) // ... mt 1396 if( lua_getmetatable( L, i)) // ... mt
@@ -1442,7 +1441,7 @@ static bool push_cached_metatable(Universe* U, Dest L2, int L2_cache_i, Source L
1442 1441
1443// ################################################################################################# 1442// #################################################################################################
1444 1443
1445static void inter_copy_keyvaluepair(Universe* U, Dest L2, int L2_cache_i, Source L, VT vt_, LookupMode mode_, char const* upName_) 1444[[nodiscard]] static void inter_copy_keyvaluepair(Universe* U, Dest L2, int L2_cache_i, Source L, VT vt_, LookupMode mode_, char const* upName_)
1446{ 1445{
1447 int val_i = lua_gettop(L); 1446 int val_i = lua_gettop(L);
1448 int key_i = val_i - 1; 1447 int key_i = val_i - 1;
@@ -1514,7 +1513,7 @@ static void inter_copy_keyvaluepair(Universe* U, Dest L2, int L2_cache_i, Source
1514*/ 1513*/
1515static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; 1514static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull };
1516 1515
1517static bool copyclone(Universe* U, Dest L2, int L2_cache_i, Source L, int source_i_, LookupMode mode_, char const* upName_) 1516[[nodiscard]] static bool copyclone(Universe* U, Dest L2, int L2_cache_i, Source L, int source_i_, LookupMode mode_, char const* upName_)
1518{ 1517{
1519 void* const source = lua_touserdata( L, source_i_); 1518 void* const source = lua_touserdata( L, source_i_);
1520 source_i_ = lua_absindex( L, source_i_); 1519 source_i_ = lua_absindex( L, source_i_);
@@ -1600,7 +1599,11 @@ static bool copyclone(Universe* U, Dest L2, int L2_cache_i, Source L, int source
1600 // assign uservalues 1599 // assign uservalues
1601 while( uvi > 0) 1600 while( uvi > 0)
1602 { 1601 {
1603 inter_copy_one(U, L2, L2_cache_i, L, lua_absindex( L, -1), VT::NORMAL, mode_, upName_); // ... u uv 1602 std::ignore = inter_copy_one(U
1603 , L2, L2_cache_i
1604 , L, lua_absindex(L, -1)
1605 , VT::NORMAL, mode_, upName_
1606 ); // ... u uv
1604 lua_pop( L, 1); // ... mt __lanesclone [uv]* 1607 lua_pop( L, 1); // ... mt __lanesclone [uv]*
1605 // this pops the value from the stack 1608 // this pops the value from the stack
1606 lua_setiuservalue( L2, -2, uvi); // ... u 1609 lua_setiuservalue( L2, -2, uvi); // ... u
@@ -1629,7 +1632,7 @@ static bool copyclone(Universe* U, Dest L2, int L2_cache_i, Source L, int source
1629 1632
1630// ################################################################################################# 1633// #################################################################################################
1631 1634
1632static bool inter_copy_userdata(Universe* U, Dest L2, int L2_cache_i, Source L, int i, VT vt_, LookupMode mode_, char const* upName_) 1635[[nodiscard]] static bool inter_copy_userdata(Universe* U, Dest L2, int L2_cache_i, Source L, int i, VT vt_, LookupMode mode_, char const* upName_)
1633{ 1636{
1634 STACK_CHECK_START_REL(L, 0); 1637 STACK_CHECK_START_REL(L, 0);
1635 STACK_CHECK_START_REL(L2, 0); 1638 STACK_CHECK_START_REL(L2, 0);
@@ -1679,7 +1682,7 @@ static bool inter_copy_userdata(Universe* U, Dest L2, int L2_cache_i, Source L,
1679 1682
1680// ################################################################################################# 1683// #################################################################################################
1681 1684
1682static bool inter_copy_function(Universe* U, Dest L2, int L2_cache_i, Source L, int source_i_, VT vt_, LookupMode mode_, char const* upName_) 1685[[nodiscard]] static bool inter_copy_function(Universe* U, Dest L2, int L2_cache_i, Source L, int source_i_, VT vt_, LookupMode mode_, char const* upName_)
1683{ 1686{
1684 if (vt_ == VT::KEY) 1687 if (vt_ == VT::KEY)
1685 { 1688 {
@@ -1693,13 +1696,10 @@ static bool inter_copy_function(Universe* U, Dest L2, int L2_cache_i, Source L,
1693 if( lua_tocfunction( L, source_i_) == userdata_clone_sentinel) // we are actually copying a clonable full userdata from a keeper 1696 if( lua_tocfunction( L, source_i_) == userdata_clone_sentinel) // we are actually copying a clonable full userdata from a keeper
1694 { 1697 {
1695 // clone the full userdata again 1698 // clone the full userdata again
1696 size_t userdata_size = 0;
1697 void* source;
1698 void* clone;
1699 1699
1700 // let's see if we already restored this userdata 1700 // let's see if we already restored this userdata
1701 lua_getupvalue( L, source_i_, 2); // ... u 1701 lua_getupvalue( L, source_i_, 2); // ... u
1702 source = lua_touserdata( L, -1); 1702 void* source = lua_touserdata( L, -1);
1703 lua_pushlightuserdata( L2, source); // ... source 1703 lua_pushlightuserdata( L2, source); // ... source
1704 lua_rawget( L2, L2_cache_i); // ... u? 1704 lua_rawget( L2, L2_cache_i); // ... u?
1705 if( !lua_isnil( L2, -1)) 1705 if( !lua_isnil( L2, -1))
@@ -1712,12 +1712,13 @@ static bool inter_copy_function(Universe* U, Dest L2, int L2_cache_i, Source L,
1712 lua_pop( L2, 1); // ... 1712 lua_pop( L2, 1); // ...
1713 1713
1714 // this function has 2 upvalues: the fqn of its metatable, and the userdata itself 1714 // this function has 2 upvalues: the fqn of its metatable, and the userdata itself
1715 lookup_table( L2, L, source_i_, mode_, upName_); // ... mt 1715 std::ignore = lookup_table( L2, L, source_i_, mode_, upName_); // ... mt
1716 // originally 'source_i_' slot was the proxy closure, but from now on it indexes the actual userdata we extracted from it 1716 // originally 'source_i_' slot was the proxy closure, but from now on it indexes the actual userdata we extracted from it
1717 source_i_ = lua_gettop( L); 1717 source_i_ = lua_gettop( L);
1718 source = lua_touserdata( L, -1); 1718 source = lua_touserdata( L, -1);
1719 void* clone{ nullptr };
1719 // get the number of bytes to allocate for the clone 1720 // get the number of bytes to allocate for the clone
1720 userdata_size = (size_t) lua_rawlen( L, -1); 1721 size_t const userdata_size { lua_rawlen(L, -1) };
1721 { 1722 {
1722 // extract uservalues (don't transfer them yet) 1723 // extract uservalues (don't transfer them yet)
1723 int uvi = 0; 1724 int uvi = 0;
@@ -1738,7 +1739,11 @@ static bool inter_copy_function(Universe* U, Dest L2, int L2_cache_i, Source L,
1738 // transfer and assign uservalues 1739 // transfer and assign uservalues
1739 while( uvi > 0) 1740 while( uvi > 0)
1740 { 1741 {
1741 inter_copy_one(U, L2, L2_cache_i, L, lua_absindex(L, -1), vt_, mode_, upName_); // ... mt u uv 1742 std::ignore = inter_copy_one(U
1743 , L2, L2_cache_i
1744 , L, lua_absindex(L, -1)
1745 , vt_, mode_, upName_
1746 ); // ... mt u uv
1742 lua_pop( L, 1); // ... u [uv]* 1747 lua_pop( L, 1); // ... u [uv]*
1743 // this pops the value from the stack 1748 // this pops the value from the stack
1744 lua_setiuservalue( L2, -2, uvi); // ... mt u 1749 lua_setiuservalue( L2, -2, uvi); // ... mt u
@@ -1774,7 +1779,7 @@ static bool inter_copy_function(Universe* U, Dest L2, int L2_cache_i, Source L,
1774 1779
1775// ################################################################################################# 1780// #################################################################################################
1776 1781
1777static bool inter_copy_table(Universe* U, Dest L2, int L2_cache_i, Source L, int i, VT vt_, LookupMode mode_, char const* upName_) 1782[[nodiscard]] static bool inter_copy_table(Universe* U, Dest L2, int L2_cache_i, Source L, int i, VT vt_, LookupMode mode_, char const* upName_)
1778{ 1783{
1779 if (vt_ == VT::KEY) 1784 if (vt_ == VT::KEY)
1780 { 1785 {
@@ -1846,7 +1851,7 @@ static bool inter_copy_table(Universe* U, Dest L2, int L2_cache_i, Source L, int
1846* 1851*
1847* Returns true if value was pushed, false if its type is non-supported. 1852* Returns true if value was pushed, false if its type is non-supported.
1848*/ 1853*/
1849bool inter_copy_one(Universe* U, Dest L2, int L2_cache_i, Source L, int i, VT vt_, LookupMode mode_, char const* upName_) 1854[[nodiscard]] bool inter_copy_one(Universe* U, Dest L2, int L2_cache_i, Source L, int i, VT vt_, LookupMode mode_, char const* upName_)
1850{ 1855{
1851 bool ret{ true }; 1856 bool ret{ true };
1852 int val_type = lua_type( L, i); 1857 int val_type = lua_type( L, i);
@@ -1971,78 +1976,77 @@ bool inter_copy_one(Universe* U, Dest L2, int L2_cache_i, Source L, int i, VT vt
1971* 1976*
1972* Note: Parameters are in this order ('L' = from first) to be same as 'lua_xmove'. 1977* Note: Parameters are in this order ('L' = from first) to be same as 'lua_xmove'.
1973*/ 1978*/
1974int luaG_inter_copy(Universe* U, Source L, Dest L2, int n, LookupMode mode_) 1979[[nodiscard]] int luaG_inter_copy(Universe* U, Source L, Dest L2, int n, LookupMode mode_)
1975{ 1980{
1976 int top_L = lua_gettop(L); // ... {}n 1981 int const top_L{ lua_gettop(L) }; // ... {}n
1977 int top_L2 = lua_gettop(L2); // ... 1982 int const top_L2{ lua_gettop(L2) }; // ...
1978 int i, j;
1979 char tmpBuf[16]; 1983 char tmpBuf[16];
1980 char const* pBuf = U->verboseErrors ? tmpBuf : "?"; 1984 char const* pBuf{ U->verboseErrors ? tmpBuf : "?" };
1981 bool copyok{ true };
1982 1985
1983 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy()\n" INDENT_END)); 1986 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "luaG_inter_copy()\n" INDENT_END));
1984 DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); 1987 DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed));
1985 1988
1986 if( n > top_L) 1989 if (n > top_L)
1987 { 1990 {
1988 // requesting to copy more than is available? 1991 // requesting to copy more than is available?
1989 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "nothing to copy()\n" INDENT_END)); 1992 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "nothing to copy()\n" INDENT_END));
1990 DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); 1993 DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed));
1991 return -1; 1994 return -1;
1992 } 1995 }
1993 1996
1994 STACK_CHECK_START_REL(L2, 0); 1997 STACK_CHECK_START_REL(L2, 0);
1995 STACK_GROW( L2, n + 1); 1998 STACK_GROW(L2, n + 1);
1996 1999
1997 /* 2000 /*
1998 * Make a cache table for the duration of this copy. Collects tables and 2001 * Make a cache table for the duration of this copy. Collects tables and
1999 * function entries, avoiding the same entries to be passed on as multiple 2002 * function entries, avoiding the same entries to be passed on as multiple
2000 * copies. ESSENTIAL i.e. for handling upvalue tables in the right manner! 2003 * copies. ESSENTIAL i.e. for handling upvalue tables in the right manner!
2001 */ 2004 */
2002 lua_newtable( L2); // ... cache 2005 lua_newtable(L2); // ... cache
2003 2006
2004 STACK_CHECK_START_REL(L, 0); 2007 STACK_CHECK_START_REL(L, 0);
2005 for( i = top_L - n + 1, j = 1; i <= top_L; ++ i, ++ j) 2008 bool copyok{ true };
2009 for (int i = top_L - n + 1, j = 1; i <= top_L; ++i, ++j)
2006 { 2010 {
2007 if( U->verboseErrors) 2011 if (U->verboseErrors)
2008 { 2012 {
2009 sprintf( tmpBuf, "arg_%d", j); 2013 sprintf(tmpBuf, "arg_%d", j);
2010 } 2014 }
2011 copyok = inter_copy_one(U, L2, top_L2 + 1, L, i, VT::NORMAL, mode_, pBuf); // ... cache {}n 2015 copyok = inter_copy_one(U, L2, top_L2 + 1, L, i, VT::NORMAL, mode_, pBuf); // ... cache {}n
2012 if( !copyok) 2016 if (!copyok)
2013 { 2017 {
2014 break; 2018 break;
2015 } 2019 }
2016 } 2020 }
2017 STACK_CHECK( L, 0); 2021 STACK_CHECK(L, 0);
2018 2022
2019 DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); 2023 DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed));
2020 2024
2021 if( copyok) 2025 if (copyok)
2022 { 2026 {
2023 STACK_CHECK( L2, n + 1); 2027 STACK_CHECK(L2, n + 1);
2024 // Remove the cache table. Persistent caching would cause i.e. multiple 2028 // Remove the cache table. Persistent caching would cause i.e. multiple
2025 // messages passed in the same table to use the same table also in receiving end. 2029 // messages passed in the same table to use the same table also in receiving end.
2026 lua_remove( L2, top_L2 + 1); 2030 lua_remove(L2, top_L2 + 1);
2027 return 0; 2031 return 0;
2028 } 2032 }
2029 2033
2030 // error -> pop everything from the target state stack 2034 // error -> pop everything from the target state stack
2031 lua_settop( L2, top_L2); 2035 lua_settop(L2, top_L2);
2032 STACK_CHECK( L2, 0); 2036 STACK_CHECK(L2, 0);
2033 return -2; 2037 return -2;
2034} 2038}
2035 2039
2036// ################################################################################################# 2040// #################################################################################################
2037 2041
2038int luaG_inter_move(Universe* U, Source L, Dest L2, int n, LookupMode mode_) 2042[[nodiscard]] int luaG_inter_move(Universe* U, Source L, Dest L2, int n, LookupMode mode_)
2039{ 2043{
2040 int ret = luaG_inter_copy( U, L, L2, n, mode_); 2044 int const ret{ luaG_inter_copy(U, L, L2, n, mode_) };
2041 lua_pop( L, (int) n); 2045 lua_pop( L, n);
2042 return ret; 2046 return ret;
2043} 2047}
2044 2048
2045int luaG_inter_copy_package(Universe* U, Source L, Dest L2, int package_idx_, LookupMode mode_) 2049[[nodiscard]] int luaG_inter_copy_package(Universe* U, Source L, Dest L2, int package_idx_, LookupMode mode_)
2046{ 2050{
2047 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "luaG_inter_copy_package()\n" INDENT_END)); 2051 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "luaG_inter_copy_package()\n" INDENT_END));
2048 DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); 2052 DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed));
@@ -2080,7 +2084,7 @@ int luaG_inter_copy_package(Universe* U, Source L, Dest L2, int package_idx_, Lo
2080 else 2084 else
2081 { 2085 {
2082 DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); 2086 DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed));
2083 luaG_inter_move(U, L, L2, 1, mode_); // moves the entry to L2 2087 std::ignore = luaG_inter_move(U, L, L2, 1, mode_); // moves the entry to L2
2084 DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); 2088 DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed));
2085 lua_setfield(L2, -2, entry); // set package[entry] 2089 lua_setfield(L2, -2, entry); // set package[entry]
2086 } 2090 }
diff --git a/src/tools.h b/src/tools.h
index 8e95a4f..f0de7ec 100644
--- a/src/tools.h
+++ b/src/tools.h
@@ -25,16 +25,16 @@ enum class VT
25 KEY, 25 KEY,
26 METATABLE 26 METATABLE
27}; 27};
28bool inter_copy_one(Universe* U, Dest L2, int L2_cache_i, Source L, int i, VT vt_, LookupMode mode_, char const* upName_); 28[[nodiscard]] bool inter_copy_one(Universe* U, Dest L2, int L2_cache_i, Source L, int i, VT vt_, LookupMode mode_, char const* upName_);
29 29
30// ################################################################################################ 30// ################################################################################################
31 31
32int luaG_inter_copy_package(Universe* U, Source L, Dest L2, int package_idx_, LookupMode mode_); 32[[nodiscard]] int luaG_inter_copy_package(Universe* U, Source L, Dest L2, int package_idx_, LookupMode mode_);
33 33
34int luaG_inter_copy(Universe* U, Source L, Dest L2, int n, LookupMode mode_); 34[[nodiscard]] int luaG_inter_copy(Universe* U, Source L, Dest L2, int n, LookupMode mode_);
35int luaG_inter_move(Universe* U, Source L, Dest L2, int n, LookupMode mode_); 35[[nodiscard]] int luaG_inter_move(Universe* U, Source L, Dest L2, int n, LookupMode mode_);
36 36
37int luaG_nameof(lua_State* L); 37[[nodiscard]] int luaG_nameof(lua_State* L);
38 38
39void populate_func_lookup_table(lua_State* L, int _i, char const* _name); 39void populate_func_lookup_table(lua_State* L, int _i, char const* _name);
40void initialize_allocator_function(Universe* U, lua_State* L); 40void initialize_allocator_function(Universe* U, lua_State* L);
diff --git a/src/universe.h b/src/universe.h
index f4211af..113ed21 100644
--- a/src/universe.h
+++ b/src/universe.h
@@ -35,7 +35,7 @@ class AllocatorDefinition
35 lua_Alloc m_allocF{ nullptr }; 35 lua_Alloc m_allocF{ nullptr };
36 void* m_allocUD{ nullptr }; 36 void* m_allocUD{ nullptr };
37 37
38 static void* operator new(size_t size_, lua_State* L) noexcept { return lua_newuserdatauv(L, size_, 0); } 38 [[nodiscard]] static void* operator new(size_t size_, lua_State* L) noexcept { return lua_newuserdatauv(L, size_, 0); }
39 // always embedded somewhere else or "in-place constructed" as a full userdata 39 // always embedded somewhere else or "in-place constructed" as a full userdata
40 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception 40 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception
41 static void operator delete([[maybe_unused]] void* p_, lua_State* L) { ASSERT_L(!"should never be called") }; 41 static void operator delete([[maybe_unused]] void* p_, lua_State* L) { ASSERT_L(!"should never be called") };
@@ -81,7 +81,7 @@ class ProtectedAllocator : public AllocatorDefinition
81 81
82 std::mutex m_lock; 82 std::mutex m_lock;
83 83
84 static void* protected_lua_Alloc(void* ud_, void* ptr_, size_t osize_, size_t nsize_) 84 [[nodiscard]] static void* protected_lua_Alloc(void* ud_, void* ptr_, size_t osize_, size_t nsize_)
85 { 85 {
86 ProtectedAllocator* const allocator{ static_cast<ProtectedAllocator*>(ud_) }; 86 ProtectedAllocator* const allocator{ static_cast<ProtectedAllocator*>(ud_) };
87 std::lock_guard<std::mutex> guard{ allocator->m_lock }; 87 std::lock_guard<std::mutex> guard{ allocator->m_lock };
@@ -91,7 +91,7 @@ class ProtectedAllocator : public AllocatorDefinition
91 public: 91 public:
92 92
93 // we are not like our base class: we can't be created inside a full userdata (or we would have to install a metatable and __gc handler to destroy ourselves properly) 93 // we are not like our base class: we can't be created inside a full userdata (or we would have to install a metatable and __gc handler to destroy ourselves properly)
94 static void* operator new(size_t size_, lua_State* L) noexcept = delete; 94 [[nodiscard]] static void* operator new(size_t size_, lua_State* L) noexcept = delete;
95 static void operator delete(void* p_, lua_State* L) = delete; 95 static void operator delete(void* p_, lua_State* L) = delete;
96 96
97 AllocatorDefinition makeDefinition() 97 AllocatorDefinition makeDefinition()
@@ -185,6 +185,6 @@ class Universe
185 185
186// ################################################################################################ 186// ################################################################################################
187 187
188Universe* universe_get(lua_State* L); 188[[nodiscard]] Universe* universe_get(lua_State* L);
189Universe* universe_create(lua_State* L); 189[[nodiscard]] Universe* universe_create(lua_State* L);
190void universe_store(lua_State* L, Universe* U); 190void universe_store(lua_State* L, Universe* U);