diff options
Diffstat (limited to 'src/keeper.cpp')
-rw-r--r-- | src/keeper.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/keeper.cpp b/src/keeper.cpp index 48f0166..c5bbb9d 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
@@ -61,10 +61,10 @@ 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 | [[nodiscard]] 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_, KeeperState 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_) { LUA_ASSERT(L_, !"should never be called"); } | 67 | static void operator delete([[maybe_unused]] void* p_, KeeperState L_) { LUA_ASSERT(L_, !"should never be called"); } |
68 | 68 | ||
69 | [[nodiscard]] static keeper_fifo* getPtr(lua_State* L, int idx_) | 69 | [[nodiscard]] static keeper_fifo* getPtr(lua_State* L, int idx_) |
70 | { | 70 | { |
@@ -95,7 +95,7 @@ static constexpr int CONTENTS_TABLE{ 1 }; | |||
95 | 95 | ||
96 | // in: nothing | 96 | // in: nothing |
97 | // out: { first = 1, count = 0, limit = -1} | 97 | // out: { first = 1, count = 0, limit = -1} |
98 | [[nodiscard]] static keeper_fifo* fifo_new(lua_State* L) | 98 | [[nodiscard]] static keeper_fifo* fifo_new(KeeperState 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); |
@@ -207,10 +207,10 @@ static void push_table(lua_State* L, int idx_) | |||
207 | 207 | ||
208 | // ################################################################################################# | 208 | // ################################################################################################# |
209 | 209 | ||
210 | int keeper_push_linda_storage(Universe* U, Dest L, void* ptr_, uintptr_t magic_) | 210 | int keeper_push_linda_storage(Universe* U, DestState L, void* ptr_, uintptr_t magic_) |
211 | { | 211 | { |
212 | Keeper* const K{ which_keeper(U->keepers, magic_) }; | 212 | Keeper* const K{ which_keeper(U->keepers, magic_) }; |
213 | Source const KL{ K ? K->L : nullptr }; | 213 | SourceState 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); // KEEPER MAIN | 216 | STACK_GROW(KL, 4); // KEEPER MAIN |
@@ -288,7 +288,7 @@ int keepercall_send(lua_State* L) | |||
288 | if (lua_isnil(L, -1)) | 288 | if (lua_isnil(L, -1)) |
289 | { | 289 | { |
290 | lua_pop(L, 1); // ud key ... fifos | 290 | lua_pop(L, 1); // ud key ... fifos |
291 | std::ignore = fifo_new(L); // ud key ... fifos fifo | 291 | std::ignore = fifo_new(KeeperState{ L }); // ud key ... fifos fifo |
292 | lua_pushvalue(L, 2); // ud key ... fifos fifo key | 292 | lua_pushvalue(L, 2); // ud key ... fifos fifo key |
293 | lua_pushvalue(L, -2); // ud key ... fifos fifo key fifo | 293 | lua_pushvalue(L, -2); // ud key ... fifos fifo key fifo |
294 | lua_rawset(L, -4); // ud key ... fifos fifo | 294 | lua_rawset(L, -4); // ud key ... fifos fifo |
@@ -396,7 +396,7 @@ int keepercall_limit(lua_State* L) | |||
396 | if (fifo == nullptr) | 396 | if (fifo == nullptr) |
397 | { // fifos key nil | 397 | { // fifos key nil |
398 | lua_pop(L, 1); // fifos key | 398 | lua_pop(L, 1); // fifos key |
399 | fifo = fifo_new(L); // fifos key fifo | 399 | fifo = fifo_new(KeeperState{ L }); // fifos key fifo |
400 | lua_rawset(L, -3); // fifos | 400 | lua_rawset(L, -3); // fifos |
401 | } | 401 | } |
402 | // remove any clutter on the stack | 402 | // remove any clutter on the stack |
@@ -466,7 +466,7 @@ int keepercall_set(lua_State* L) | |||
466 | { // fifos key [val [, ...]] nil | 466 | { // fifos key [val [, ...]] nil |
467 | // no need to wake writers in that case, because a writer can't wait on an inexistent key | 467 | // no need to wake writers in that case, because a writer can't wait on an inexistent key |
468 | lua_pop(L, 1); // fifos key [val [, ...]] | 468 | lua_pop(L, 1); // fifos key [val [, ...]] |
469 | std::ignore = fifo_new(L); // fifos key [val [, ...]] fifo | 469 | std::ignore = fifo_new(KeeperState{ L }); // fifos key [val [, ...]] fifo |
470 | lua_pushvalue(L, 2); // fifos key [val [, ...]] fifo key | 470 | lua_pushvalue(L, 2); // fifos key [val [, ...]] fifo key |
471 | lua_pushvalue(L, -2); // fifos key [val [, ...]] fifo key fifo | 471 | lua_pushvalue(L, -2); // fifos key [val [, ...]] fifo key fifo |
472 | lua_rawset(L, 1); // fifos key [val [, ...]] fifo | 472 | lua_rawset(L, 1); // fifos key [val [, ...]] fifo |
@@ -615,7 +615,7 @@ void close_keepers(Universe* U) | |||
615 | for (int i = 0; i < nbKeepers; ++i) | 615 | for (int i = 0; i < nbKeepers; ++i) |
616 | { | 616 | { |
617 | lua_State* K = U->keepers->keeper_array[i].L; | 617 | lua_State* K = U->keepers->keeper_array[i].L; |
618 | U->keepers->keeper_array[i].L = nullptr; | 618 | U->keepers->keeper_array[i].L = KeeperState{ nullptr }; |
619 | if (K != nullptr) | 619 | if (K != nullptr) |
620 | { | 620 | { |
621 | lua_close(K); | 621 | lua_close(K); |
@@ -687,7 +687,7 @@ void init_keepers(Universe* U, lua_State* L) | |||
687 | for (int i = 0; i < nb_keepers; ++i) // settings | 687 | for (int i = 0; i < nb_keepers; ++i) // settings |
688 | { | 688 | { |
689 | // note that we will leak K if we raise an error later | 689 | // note that we will leak K if we raise an error later |
690 | lua_State* const K{ create_state(U, L) }; | 690 | KeeperState const K{ create_state(U, L) }; |
691 | if (K == nullptr) | 691 | if (K == nullptr) |
692 | { | 692 | { |
693 | luaL_error(L, "init_keepers() failed while creating keeper states; out of memory"); // doesn't return | 693 | luaL_error(L, "init_keepers() failed while creating keeper states; out of memory"); // doesn't return |
@@ -719,7 +719,7 @@ void init_keepers(Universe* U, lua_State* L) | |||
719 | if (!lua_isnil(L, -1)) | 719 | if (!lua_isnil(L, -1)) |
720 | { | 720 | { |
721 | // when copying with mode LookupMode::ToKeeper, error message is pushed at the top of the stack, not raised immediately | 721 | // when copying with mode LookupMode::ToKeeper, error message is pushed at the top of the stack, not raised immediately |
722 | InterCopyContext c{ U, Dest{ K }, Source{ L }, {}, SourceIndex{ lua_absindex(L, -1) }, {}, LookupMode::ToKeeper, {} }; | 722 | InterCopyContext c{ U, DestState{ K }, SourceState{ L }, {}, SourceIndex{ lua_absindex(L, -1) }, {}, LookupMode::ToKeeper, {} }; |
723 | if (c.inter_copy_package() != InterCopyResult::Success) | 723 | if (c.inter_copy_package() != InterCopyResult::Success) |
724 | { | 724 | { |
725 | // if something went wrong, the error message is at the top of the stack | 725 | // if something went wrong, the error message is at the top of the stack |
@@ -832,7 +832,7 @@ void keeper_toggle_nil_sentinels(lua_State* L, int val_i_, LookupMode const mode | |||
832 | * | 832 | * |
833 | * Returns: number of return values (pushed to 'L'), unset in case of error | 833 | * Returns: number of return values (pushed to 'L'), unset in case of error |
834 | */ | 834 | */ |
835 | KeeperCallResult keeper_call(Universe* U, lua_State* K, keeper_api_t func_, lua_State* L, void* linda, int starting_index) | 835 | KeeperCallResult keeper_call(Universe* U, KeeperState K, keeper_api_t func_, lua_State* L, void* linda, int starting_index) |
836 | { | 836 | { |
837 | KeeperCallResult result; | 837 | KeeperCallResult result; |
838 | int const args{ starting_index ? (lua_gettop(L) - starting_index + 1) : 0 }; | 838 | int const args{ starting_index ? (lua_gettop(L) - starting_index + 1) : 0 }; |
@@ -845,7 +845,7 @@ KeeperCallResult keeper_call(Universe* U, lua_State* K, keeper_api_t func_, lua_ | |||
845 | lua_pushlightuserdata(K, linda); // func_ linda | 845 | lua_pushlightuserdata(K, linda); // func_ linda |
846 | if ( | 846 | if ( |
847 | (args == 0) || | 847 | (args == 0) || |
848 | (InterCopyContext{ U, Dest{ K }, Source{ L }, {}, {}, {}, LookupMode::ToKeeper, {} }.inter_copy(args) == InterCopyResult::Success) | 848 | (InterCopyContext{ U, DestState{ K }, SourceState{ L }, {}, {}, {}, LookupMode::ToKeeper, {} }.inter_copy(args) == InterCopyResult::Success) |
849 | ) | 849 | ) |
850 | { // func_ linda args... | 850 | { // func_ linda args... |
851 | lua_call(K, 1 + args, LUA_MULTRET); // result... | 851 | lua_call(K, 1 + args, LUA_MULTRET); // result... |
@@ -856,7 +856,7 @@ KeeperCallResult keeper_call(Universe* U, lua_State* K, keeper_api_t func_, lua_ | |||
856 | // when attempting to grab the mutex again (WINVER <= 0x400 does this, but locks just fine, I don't know about pthread) | 856 | // when attempting to grab the mutex again (WINVER <= 0x400 does this, but locks just fine, I don't know about pthread) |
857 | if ( | 857 | if ( |
858 | (retvals == 0) || | 858 | (retvals == 0) || |
859 | (InterCopyContext{ U, Dest{ L }, Source{ K }, {}, {}, {}, LookupMode::FromKeeper, {} }.inter_move(retvals) == InterCopyResult::Success) | 859 | (InterCopyContext{ U, DestState{ L }, SourceState{ K }, {}, {}, {}, LookupMode::FromKeeper, {} }.inter_move(retvals) == InterCopyResult::Success) |
860 | ) // K->L | 860 | ) // K->L |
861 | { | 861 | { |
862 | result.emplace(retvals); | 862 | result.emplace(retvals); |