aboutsummaryrefslogtreecommitdiff
path: root/src/keeper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/keeper.cpp')
-rw-r--r--src/keeper.cpp58
1 files changed, 29 insertions, 29 deletions
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