aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-04-24 15:53:04 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-04-24 15:53:04 +0200
commit45fab6f5b12f00631005b0086931a2f25385146e (patch)
tree2ff35ec89c2622d6624a691874879d1fdca09006 /src
parent3bfb6dec957e5e034c12157787fab9faf75c85a1 (diff)
downloadlanes-45fab6f5b12f00631005b0086931a2f25385146e.tar.gz
lanes-45fab6f5b12f00631005b0086931a2f25385146e.tar.bz2
lanes-45fab6f5b12f00631005b0086931a2f25385146e.zip
C++ migration: using KeeperState = Unique<lua_State*>
Diffstat (limited to 'src')
-rw-r--r--src/deep.cpp4
-rw-r--r--src/deep.h4
-rw-r--r--src/keeper.cpp28
-rw-r--r--src/keeper.h8
-rw-r--r--src/lanes.cpp18
-rw-r--r--src/linda.cpp10
-rw-r--r--src/macros_and_utils.h4
-rw-r--r--src/state.cpp8
-rw-r--r--src/state.h2
-rw-r--r--src/tools.cpp2
-rw-r--r--src/tools.h4
11 files changed, 47 insertions, 45 deletions
diff --git a/src/deep.cpp b/src/deep.cpp
index e4d090f..241cb95 100644
--- a/src/deep.cpp
+++ b/src/deep.cpp
@@ -191,7 +191,7 @@ void DeepFactory::DeleteDeepObject(lua_State* L, DeepPrelude* o_)
191 * used in this Lua state (metatable, registring it). Otherwise, increments the 191 * used in this Lua state (metatable, registring it). Otherwise, increments the
192 * reference count. 192 * reference count.
193 */ 193 */
194char const* DeepFactory::PushDeepProxy(Dest L, DeepPrelude* prelude, int nuv_, LookupMode mode_) 194char const* DeepFactory::PushDeepProxy(DestState L, DeepPrelude* prelude, int nuv_, LookupMode mode_)
195{ 195{
196 // Check if a proxy already exists 196 // Check if a proxy already exists
197 push_registry_subtable_mode(L, DEEP_PROXY_CACHE_KEY, "v"); // DPC 197 push_registry_subtable_mode(L, DEEP_PROXY_CACHE_KEY, "v"); // DPC
@@ -343,7 +343,7 @@ char const* DeepFactory::PushDeepProxy(Dest L, DeepPrelude* prelude, int nuv_, L
343* 343*
344* Returns: 'proxy' userdata for accessing the deep data via 'DeepFactory::toDeep()' 344* Returns: 'proxy' userdata for accessing the deep data via 'DeepFactory::toDeep()'
345*/ 345*/
346int DeepFactory::pushDeepUserdata(Dest L, int nuv_) const 346int DeepFactory::pushDeepUserdata(DestState L, int nuv_) const
347{ 347{
348 STACK_GROW( L, 1); 348 STACK_GROW( L, 1);
349 STACK_CHECK_START_REL(L, 0); 349 STACK_CHECK_START_REL(L, 0);
diff --git a/src/deep.h b/src/deep.h
index 95802d1..28069fe 100644
--- a/src/deep.h
+++ b/src/deep.h
@@ -77,8 +77,8 @@ class DeepFactory
77 public: 77 public:
78 78
79 // NVI: public interface 79 // NVI: public interface
80 int pushDeepUserdata(Dest L, int nuv_) const; 80 int pushDeepUserdata(DestState L, int nuv_) const;
81 DeepPrelude* toDeep(lua_State* L, int index) const; 81 DeepPrelude* toDeep(lua_State* L, int index) const;
82 static void DeleteDeepObject(lua_State* L, DeepPrelude* o_); 82 static void DeleteDeepObject(lua_State* L, DeepPrelude* o_);
83 static char const* PushDeepProxy(Dest L, DeepPrelude* prelude, int nuv_, LookupMode mode_); 83 static char const* PushDeepProxy(DestState L, DeepPrelude* prelude, int nuv_, LookupMode mode_);
84}; 84};
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
210int keeper_push_linda_storage(Universe* U, Dest L, void* ptr_, uintptr_t magic_) 210int 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*/
835KeeperCallResult keeper_call(Universe* U, lua_State* K, keeper_api_t func_, lua_State* L, void* linda, int starting_index) 835KeeperCallResult 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);
diff --git a/src/keeper.h b/src/keeper.h
index 30de3a6..ef86f94 100644
--- a/src/keeper.h
+++ b/src/keeper.h
@@ -18,10 +18,12 @@ extern "C" {
18enum class LookupMode; 18enum class LookupMode;
19class Universe; 19class Universe;
20 20
21using KeeperState = Unique<lua_State*>;
22
21struct Keeper 23struct Keeper
22{ 24{
23 std::mutex m_mutex; 25 std::mutex m_mutex;
24 lua_State* L{ nullptr }; 26 KeeperState L{ nullptr };
25 // int count; 27 // int count;
26}; 28};
27 29
@@ -43,7 +45,7 @@ void close_keepers(Universe* U);
43[[nodiscard]] Keeper* keeper_acquire(Keepers* keepers_, uintptr_t magic_); 45[[nodiscard]] Keeper* keeper_acquire(Keepers* keepers_, uintptr_t magic_);
44void keeper_release(Keeper* K_); 46void keeper_release(Keeper* K_);
45void keeper_toggle_nil_sentinels(lua_State* L, int val_i_, LookupMode const mode_); 47void keeper_toggle_nil_sentinels(lua_State* L, int val_i_, LookupMode const mode_);
46[[nodiscard]] int keeper_push_linda_storage(Universe* U, Dest L, void* ptr_, uintptr_t magic_); 48[[nodiscard]] int keeper_push_linda_storage(Universe* U, DestState L, void* ptr_, uintptr_t magic_);
47 49
48using keeper_api_t = lua_CFunction; 50using keeper_api_t = lua_CFunction;
49#define KEEPER_API(_op) keepercall_##_op 51#define KEEPER_API(_op) keepercall_##_op
@@ -59,4 +61,4 @@ using keeper_api_t = lua_CFunction;
59[[nodiscard]] int keepercall_count(lua_State* L); 61[[nodiscard]] int keepercall_count(lua_State* L);
60 62
61using KeeperCallResult = Unique<std::optional<int>>; 63using KeeperCallResult = Unique<std::optional<int>>;
62[[nodiscard]] KeeperCallResult keeper_call(Universe* U, lua_State* K, keeper_api_t _func, lua_State* L, void* linda, int starting_index); 64[[nodiscard]] KeeperCallResult keeper_call(Universe* U, KeeperState K, keeper_api_t _func, lua_State* L, void* linda, int starting_index);
diff --git a/src/lanes.cpp b/src/lanes.cpp
index 880c150..d549449 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -1001,7 +1001,7 @@ LUAG_FUNC(lane_new)
1001 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: setup\n" INDENT_END)); 1001 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: setup\n" INDENT_END));
1002 1002
1003 // populate with selected libraries at the same time 1003 // populate with selected libraries at the same time
1004 lua_State* const L2{ luaG_newstate(U, Source{ L }, libs_str) }; // L // L2 1004 lua_State* const L2{ luaG_newstate(U, SourceState{ L }, libs_str) }; // L // L2
1005 1005
1006 // 'lane' is allocated from heap, not Lua, since its life span may surpass the handle's (if free running thread) 1006 // 'lane' is allocated from heap, not Lua, since its life span may surpass the handle's (if free running thread)
1007 Lane* const lane{ new (U) Lane{ U, L2 } }; 1007 Lane* const lane{ new (U) Lane{ U, L2 } };
@@ -1111,7 +1111,7 @@ LUAG_FUNC(lane_new)
1111 { 1111 {
1112 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: update 'package'\n" INDENT_END)); 1112 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: update 'package'\n" INDENT_END));
1113 // when copying with mode LookupMode::LaneBody, should raise an error in case of problem, not leave it one the stack 1113 // when copying with mode LookupMode::LaneBody, should raise an error in case of problem, not leave it one the stack
1114 InterCopyContext c{ U, Dest{ L2 }, Source{ L }, {}, SourceIndex{ package_idx }, {}, {}, {} }; 1114 InterCopyContext c{ U, DestState{ L2 }, SourceState{ L }, {}, SourceIndex{ package_idx }, {}, {}, {} };
1115 [[maybe_unused]] InterCopyResult const ret{ c.inter_copy_package() }; 1115 [[maybe_unused]] InterCopyResult const ret{ c.inter_copy_package() };
1116 LUA_ASSERT(L, ret == InterCopyResult::Success); // either all went well, or we should not even get here 1116 LUA_ASSERT(L, ret == InterCopyResult::Success); // either all went well, or we should not even get here
1117 } 1117 }
@@ -1155,7 +1155,7 @@ LUAG_FUNC(lane_new)
1155 if (lua_pcall( L2, 1, 1, 0) != LUA_OK) // ret/errcode 1155 if (lua_pcall( L2, 1, 1, 0) != LUA_OK) // ret/errcode
1156 { 1156 {
1157 // propagate error to main state if any 1157 // propagate error to main state if any
1158 InterCopyContext c{ U, Dest{ L }, Source{ L2 }, {}, {}, {}, {}, {} }; 1158 InterCopyContext c{ U, DestState{ L }, SourceState{ L2 }, {}, {}, {}, {}, {} };
1159 std::ignore = c.inter_move(1); // func libs priority globals package required gc_cb [... args ...] n "modname" error 1159 std::ignore = c.inter_move(1); // func libs priority globals package required gc_cb [... args ...] n "modname" error
1160 raise_lua_error(L); 1160 raise_lua_error(L);
1161 } 1161 }
@@ -1185,7 +1185,7 @@ LUAG_FUNC(lane_new)
1185 DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); 1185 DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U });
1186 lua_pushnil(L); // func libs priority globals package required gc_cb [... args ...] nil 1186 lua_pushnil(L); // func libs priority globals package required gc_cb [... args ...] nil
1187 // Lua 5.2 wants us to push the globals table on the stack 1187 // Lua 5.2 wants us to push the globals table on the stack
1188 InterCopyContext c{ U, Dest{ L2 }, Source{ L }, {}, {}, {}, {}, {} }; 1188 InterCopyContext c{ U, DestState{ L2 }, SourceState{ L }, {}, {}, {}, {}, {} };
1189 lua_pushglobaltable(L2); // _G 1189 lua_pushglobaltable(L2); // _G
1190 while( lua_next(L, globals_idx)) // func libs priority globals package required gc_cb [... args ...] k v 1190 while( lua_next(L, globals_idx)) // func libs priority globals package required gc_cb [... args ...] k v
1191 { 1191 {
@@ -1206,7 +1206,7 @@ LUAG_FUNC(lane_new)
1206 DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "lane_new: transfer lane body\n" INDENT_END)); 1206 DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "lane_new: transfer lane body\n" INDENT_END));
1207 DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); 1207 DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U });
1208 lua_pushvalue(L, 1); // func libs priority globals package required gc_cb [... args ...] func 1208 lua_pushvalue(L, 1); // func libs priority globals package required gc_cb [... args ...] func
1209 InterCopyContext c{ U, Dest{ L2 }, Source{ L }, {}, {}, {}, {}, {} }; 1209 InterCopyContext c{ U, DestState{ L2 }, SourceState{ L }, {}, {}, {}, {}, {} };
1210 InterCopyResult const res{ c.inter_move(1) }; // func libs priority globals package required gc_cb [... args ...] // func 1210 InterCopyResult const res{ c.inter_move(1) }; // func libs priority globals package required gc_cb [... args ...] // func
1211 if (res != InterCopyResult::Success) 1211 if (res != InterCopyResult::Success)
1212 { 1212 {
@@ -1235,7 +1235,7 @@ LUAG_FUNC(lane_new)
1235 { 1235 {
1236 DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "lane_new: transfer lane arguments\n" INDENT_END)); 1236 DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "lane_new: transfer lane arguments\n" INDENT_END));
1237 DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); 1237 DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U });
1238 InterCopyContext c{ U, Dest{ L2 }, Source{ L }, {}, {}, {}, {}, {} }; 1238 InterCopyContext c{ U, DestState{ L2 }, SourceState{ L }, {}, {}, {}, {}, {} };
1239 InterCopyResult const res{ c.inter_move(nargs) }; // func libs priority globals package required gc_cb // func [... args ...] 1239 InterCopyResult const res{ c.inter_move(nargs) }; // func libs priority globals package required gc_cb // func [... args ...]
1240 if (res != InterCopyResult::Success) 1240 if (res != InterCopyResult::Success)
1241 { 1241 {
@@ -1402,7 +1402,7 @@ LUAG_FUNC(thread_join)
1402 int const n{ lua_gettop(L2) }; // whole L2 stack 1402 int const n{ lua_gettop(L2) }; // whole L2 stack
1403 if ( 1403 if (
1404 (n > 0) && 1404 (n > 0) &&
1405 (InterCopyContext{ U, Dest{ L }, Source{ L2 }, {}, {}, {}, {}, {} }.inter_move(n) != InterCopyResult::Success) 1405 (InterCopyContext{ U, DestState{ L }, SourceState{ L2 }, {}, {}, {}, {}, {} }.inter_move(n) != InterCopyResult::Success)
1406 ) 1406 )
1407 { 1407 {
1408 luaL_error(L, "tried to copy unsupported types"); // doesn't return 1408 luaL_error(L, "tried to copy unsupported types"); // doesn't return
@@ -1417,7 +1417,7 @@ LUAG_FUNC(thread_join)
1417 STACK_GROW(L, 3); 1417 STACK_GROW(L, 3);
1418 lua_pushnil(L); 1418 lua_pushnil(L);
1419 // even when ERROR_FULL_STACK, if the error is not LUA_ERRRUN, the handler wasn't called, and we only have 1 error message on the stack ... 1419 // even when ERROR_FULL_STACK, if the error is not LUA_ERRRUN, the handler wasn't called, and we only have 1 error message on the stack ...
1420 InterCopyContext c{ U, Dest{ L }, Source{ L2 }, {}, {}, {}, {}, {} }; 1420 InterCopyContext c{ U, DestState{ L }, SourceState{ L2 }, {}, {}, {}, {}, {} };
1421 if (c.inter_move(n) != InterCopyResult::Success) // nil "err" [trace] 1421 if (c.inter_move(n) != InterCopyResult::Success) // nil "err" [trace]
1422 { 1422 {
1423 luaL_error(L, "tried to copy unsupported types: %s", lua_tostring(L, -n)); // doesn't return 1423 luaL_error(L, "tried to copy unsupported types: %s", lua_tostring(L, -n)); // doesn't return
@@ -1815,7 +1815,7 @@ LUAG_FUNC(configure)
1815 STACK_CHECK(L, 2); 1815 STACK_CHECK(L, 2);
1816 1816
1817 { 1817 {
1818 char const* errmsg{ DeepFactory::PushDeepProxy(Dest{ L }, U->timer_deep, 0, LookupMode::LaneBody) }; // settings M timer_deep 1818 char const* errmsg{ DeepFactory::PushDeepProxy(DestState{ L }, U->timer_deep, 0, LookupMode::LaneBody) }; // settings M timer_deep
1819 if (errmsg != nullptr) 1819 if (errmsg != nullptr)
1820 { 1820 {
1821 return luaL_error(L, errmsg); 1821 return luaL_error(L, errmsg);
diff --git a/src/linda.cpp b/src/linda.cpp
index 4635d75..a19b126 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -307,7 +307,7 @@ LUAG_FUNC(linda_send)
307 { 307 {
308 Lane* const lane{ LANE_POINTER_REGKEY.readLightUserDataValue<Lane>(L) }; 308 Lane* const lane{ LANE_POINTER_REGKEY.readLightUserDataValue<Lane>(L) };
309 Keeper* const K{ which_keeper(linda->U->keepers, linda->hashSeed()) }; 309 Keeper* const K{ which_keeper(linda->U->keepers, linda->hashSeed()) };
310 lua_State* const KL{ K ? K->L : nullptr }; 310 KeeperState const KL{ K ? K->L : nullptr };
311 if (KL == nullptr) 311 if (KL == nullptr)
312 return 0; 312 return 0;
313 313
@@ -473,7 +473,7 @@ LUAG_FUNC(linda_receive)
473 473
474 Lane* const lane{ LANE_POINTER_REGKEY.readLightUserDataValue<Lane>(L) }; 474 Lane* const lane{ LANE_POINTER_REGKEY.readLightUserDataValue<Lane>(L) };
475 Keeper* const K{ which_keeper(linda->U->keepers, linda->hashSeed()) }; 475 Keeper* const K{ which_keeper(linda->U->keepers, linda->hashSeed()) };
476 lua_State* const KL{ K ? K->L : nullptr }; 476 KeeperState const KL{ K ? K->L : nullptr };
477 if (KL == nullptr) 477 if (KL == nullptr)
478 return 0; 478 return 0;
479 479
@@ -863,7 +863,7 @@ LUAG_FUNC(linda_dump)
863 auto dump = [](lua_State* L) 863 auto dump = [](lua_State* L)
864 { 864 {
865 Linda* const linda{ ToLinda<false>(L, 1) }; 865 Linda* const linda{ ToLinda<false>(L, 1) };
866 return keeper_push_linda_storage(linda->U, Dest{ L }, linda, linda->hashSeed()); 866 return keeper_push_linda_storage(linda->U, DestState{ L }, linda, linda->hashSeed());
867 }; 867 };
868 return Linda::ProtectedCall(L, dump); 868 return Linda::ProtectedCall(L, dump);
869} 869}
@@ -877,7 +877,7 @@ LUAG_FUNC(linda_dump)
877LUAG_FUNC(linda_towatch) 877LUAG_FUNC(linda_towatch)
878{ 878{
879 Linda* const linda{ ToLinda<false>(L, 1) }; 879 Linda* const linda{ ToLinda<false>(L, 1) };
880 int pushed{ keeper_push_linda_storage(linda->U, Dest{ L }, linda, linda->hashSeed()) }; 880 int pushed{ keeper_push_linda_storage(linda->U, DestState{ L }, linda, linda->hashSeed()) };
881 if (pushed == 0) 881 if (pushed == 0)
882 { 882 {
883 // if the linda is empty, don't return nil 883 // if the linda is empty, don't return nil
@@ -1028,5 +1028,5 @@ LUAG_FUNC(linda)
1028 luaL_checktype(L, 1, LUA_TSTRING); 1028 luaL_checktype(L, 1, LUA_TSTRING);
1029 luaL_checktype(L, 2, LUA_TNUMBER); 1029 luaL_checktype(L, 2, LUA_TNUMBER);
1030 } 1030 }
1031 return g_LindaFactory.pushDeepUserdata(Dest{ L }, 0); 1031 return g_LindaFactory.pushDeepUserdata(DestState{ L }, 0);
1032} 1032}
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h
index edda76e..068ff26 100644
--- a/src/macros_and_utils.h
+++ b/src/macros_and_utils.h
@@ -206,8 +206,8 @@ class Unique<T, lambda, std::enable_if_t<!std::is_scalar_v<T>>> : public T
206 206
207// ################################################################################################# 207// #################################################################################################
208 208
209using Source = Unique<lua_State*>; 209using SourceState = Unique<lua_State*>;
210using Dest = Unique<lua_State*>; 210using DestState = Unique<lua_State*>;
211 211
212// ################################################################################################# 212// #################################################################################################
213 213
diff --git a/src/state.cpp b/src/state.cpp
index 9ad237d..2a69a46 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -190,7 +190,7 @@ static void open1lib(DEBUGSPEW_PARAM_COMMA(Universe* U) lua_State* L, char const
190// ################################################################################################# 190// #################################################################################################
191 191
192// just like lua_xmove, args are (from, to) 192// just like lua_xmove, args are (from, to)
193static void copy_one_time_settings(Universe* U, Source L1, Dest L2) 193static void copy_one_time_settings(Universe* U, SourceState L1, DestState L2)
194{ 194{
195 DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); 195 DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U });
196 196
@@ -331,9 +331,9 @@ void call_on_state_create(Universe* U, lua_State* L, lua_State* from_, LookupMod
331* *NOT* called for keeper states! 331* *NOT* called for keeper states!
332* 332*
333*/ 333*/
334lua_State* luaG_newstate(Universe* U, Source from_, char const* libs_) 334lua_State* luaG_newstate(Universe* U, SourceState from_, char const* libs_)
335{ 335{
336 Dest const L{ create_state(U, from_) }; 336 DestState const L{ create_state(U, from_) };
337 337
338 STACK_GROW(L, 2); 338 STACK_GROW(L, 2);
339 STACK_CHECK_START_ABS(L, 0); 339 STACK_CHECK_START_ABS(L, 0);
@@ -361,7 +361,7 @@ lua_State* luaG_newstate(Universe* U, Source from_, char const* libs_)
361 copy_one_time_settings( U, from_, L); 361 copy_one_time_settings( U, from_, L);
362 362
363 // 'lua.c' stops GC during initialization so perhaps its a good idea. :) 363 // 'lua.c' stops GC during initialization so perhaps its a good idea. :)
364 lua_gc( L, LUA_GCSTOP, 0); 364 lua_gc(L, LUA_GCSTOP, 0);
365 365
366 366
367 // Anything causes 'base' to be taken in 367 // Anything causes 'base' to be taken in
diff --git a/src/state.h b/src/state.h
index 059e163..2d65f16 100644
--- a/src/state.h
+++ b/src/state.h
@@ -11,7 +11,7 @@ void serialize_require(DEBUGSPEW_PARAM_COMMA(Universe* U) lua_State* L);
11// ################################################################################################# 11// #################################################################################################
12 12
13[[nodiscard]] lua_State* create_state(Universe* U, lua_State* from_); 13[[nodiscard]] lua_State* create_state(Universe* U, lua_State* from_);
14[[nodiscard]] lua_State* luaG_newstate(Universe* U, Source _from, char const* libs); 14[[nodiscard]] lua_State* luaG_newstate(Universe* U, SourceState _from, char const* libs);
15 15
16// ################################################################################################# 16// #################################################################################################
17 17
diff --git a/src/tools.cpp b/src/tools.cpp
index e2ce8b8..a25fb2b 100644
--- a/src/tools.cpp
+++ b/src/tools.cpp
@@ -751,7 +751,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull };
751 * Returns true if the table was cached (no need to fill it!); false if 751 * Returns true if the table was cached (no need to fill it!); false if
752 * it's a virgin. 752 * it's a virgin.
753 */ 753 */
754[[nodiscard]] static bool push_cached_table(Dest L2, CacheIndex L2_cache_i, Source L1, SourceIndex i) 754[[nodiscard]] static bool push_cached_table(DestState L2, CacheIndex L2_cache_i, SourceState L1, SourceIndex i)
755{ 755{
756 void const* p{ lua_topointer(L1, i) }; 756 void const* p{ lua_topointer(L1, i) };
757 757
diff --git a/src/tools.h b/src/tools.h
index 673d6f0..755a0c6 100644
--- a/src/tools.h
+++ b/src/tools.h
@@ -34,8 +34,8 @@ class InterCopyContext
34 public: 34 public:
35 35
36 Universe* const U; 36 Universe* const U;
37 Dest const L2; 37 DestState const L2;
38 Source const L1; 38 SourceState const L1;
39 CacheIndex const L2_cache_i; 39 CacheIndex const L2_cache_i;
40 SourceIndex L1_i; // that one can change when we reuse the context 40 SourceIndex L1_i; // that one can change when we reuse the context
41 VT vt; // that one can change when we reuse the context 41 VT vt; // that one can change when we reuse the context