aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-04-26 10:17:09 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-04-26 10:17:09 +0200
commit4343dc14c1db7ef9e5d57ed1d40740439e1c51d6 (patch)
treee3e7d192218291e4d089835fd63ac052142aa673 /src
parent0b5108a8a0d9b7a4a63bd6aae0271b71a887beea (diff)
downloadlanes-4343dc14c1db7ef9e5d57ed1d40740439e1c51d6.tar.gz
lanes-4343dc14c1db7ef9e5d57ed1d40740439e1c51d6.tar.bz2
lanes-4343dc14c1db7ef9e5d57ed1d40740439e1c51d6.zip
Formalize a few coding style rules, start to enforce them for constants
Diffstat (limited to 'src')
-rw-r--r--src/cancel.cpp2
-rw-r--r--src/cancel.h6
-rw-r--r--src/deep.cpp18
-rw-r--r--src/deep.h6
-rw-r--r--src/keeper.cpp72
-rw-r--r--src/keeper.h4
-rw-r--r--src/lanes.cpp170
-rw-r--r--src/lanes_private.h4
-rw-r--r--src/lanesconf.h26
-rw-r--r--src/linda.cpp42
-rw-r--r--src/linda.h1
-rw-r--r--src/state.cpp12
-rw-r--r--src/threading.cpp2
-rw-r--r--src/threading.h12
-rw-r--r--src/tools.cpp74
-rw-r--r--src/tools.h8
-rw-r--r--src/universe.cpp16
-rw-r--r--src/universe.h1
18 files changed, 251 insertions, 225 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp
index 5bcf79d..0ec5eb5 100644
--- a/src/cancel.cpp
+++ b/src/cancel.cpp
@@ -53,7 +53,7 @@ THE SOFTWARE.
53*/ 53*/
54[[nodiscard]] static 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{ kLanePointerRegKey.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)
58 return lane ? lane->cancel_request : CancelRequest::None; 58 return lane ? lane->cancel_request : CancelRequest::None;
59} 59}
diff --git a/src/cancel.h b/src/cancel.h
index a25c078..d5c3f7b 100644
--- a/src/cancel.h
+++ b/src/cancel.h
@@ -44,8 +44,8 @@ enum class CancelOp
44 MaskCount = LUA_MASKCOUNT, 44 MaskCount = LUA_MASKCOUNT,
45}; 45};
46 46
47// crc64/we of string "CANCEL_ERROR" generated at http://www.nitrxgen.net/hashgen/ 47// xxh64 of string "kCancelError" generated at https://www.pelock.com/products/hash-calculator
48static constexpr UniqueKey CANCEL_ERROR{ 0xE97D41626CC97577ull, "lanes.cancel_error" }; // 'raise_cancel_error' sentinel 48static constexpr UniqueKey kCancelError{ 0x0630345FEF912746ull, "lanes.cancel_error" }; // 'raise_cancel_error' sentinel
49 49
50[[nodiscard]] CancelOp which_cancel_op(char const* op_string_); 50[[nodiscard]] CancelOp which_cancel_op(char const* op_string_);
51[[nodiscard]] CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hook_count_, lua_Duration secs_, bool wake_lindas_); 51[[nodiscard]] CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hook_count_, lua_Duration secs_, bool wake_lindas_);
@@ -53,7 +53,7 @@ static constexpr UniqueKey CANCEL_ERROR{ 0xE97D41626CC97577ull, "lanes.cancel_er
53[[noreturn]] static inline void raise_cancel_error(lua_State* L) 53[[noreturn]] static inline void raise_cancel_error(lua_State* L)
54{ 54{
55 STACK_GROW(L, 1); 55 STACK_GROW(L, 1);
56 CANCEL_ERROR.pushKey(L); // special error value 56 kCancelError.pushKey(L); // special error value
57 raise_lua_error(L); // doesn't return 57 raise_lua_error(L); // doesn't return
58} 58}
59 59
diff --git a/src/deep.cpp b/src/deep.cpp
index 241cb95..d7efe68 100644
--- a/src/deep.cpp
+++ b/src/deep.cpp
@@ -53,14 +53,14 @@ THE SOFTWARE.
53* metatable -> factory 53* metatable -> factory
54* factory -> metatable 54* factory -> metatable
55*/ 55*/
56// crc64/we of string "DEEP_LOOKUP_KEY" generated at http://www.nitrxgen.net/hashgen/ 56// xxh64 of string "kDeepLookupRegKey" generated at https://www.pelock.com/products/hash-calculator
57static constexpr RegistryUniqueKey DEEP_LOOKUP_KEY{ 0x9FB9B4F3F633D83Dull }; 57static constexpr RegistryUniqueKey kDeepLookupRegKey{ 0xC6788345703C6059ull };
58 58
59/* 59/*
60 * The deep proxy cache is a weak valued table listing all deep UD proxies indexed by the deep UD that they are proxying 60 * The deep proxy cache is a weak valued table listing all deep UD proxies indexed by the deep UD that they are proxying
61 * crc64/we of string "DEEP_PROXY_CACHE_KEY" generated at http://www.nitrxgen.net/hashgen/ 61 * xxh64 of string "kDeepProxyCacheRegKey" generated at https://www.pelock.com/products/hash-calculator
62*/ 62*/
63static constexpr RegistryUniqueKey DEEP_PROXY_CACHE_KEY{ 0x05773D6FC26BE106ull }; 63static constexpr RegistryUniqueKey kDeepProxyCacheRegKey{ 0xEBCD49AE1A3DD35Eull };
64 64
65/* 65/*
66* Sets up [-1]<->[-2] two-way lookups, and ensures the lookup table exists. 66* Sets up [-1]<->[-2] two-way lookups, and ensures the lookup table exists.
@@ -70,7 +70,7 @@ static void set_deep_lookup(lua_State* L)
70{ 70{
71 STACK_GROW( L, 3); 71 STACK_GROW( L, 3);
72 STACK_CHECK_START_REL(L, 2); // a b 72 STACK_CHECK_START_REL(L, 2); // a b
73 push_registry_subtable( L, DEEP_LOOKUP_KEY); // a b {} 73 push_registry_subtable( L, kDeepLookupRegKey); // a b {}
74 STACK_CHECK( L, 3); 74 STACK_CHECK( L, 3);
75 lua_insert( L, -3); // {} a b 75 lua_insert( L, -3); // {} a b
76 lua_pushvalue( L, -1); // {} a b b 76 lua_pushvalue( L, -1); // {} a b b
@@ -91,7 +91,7 @@ static void get_deep_lookup(lua_State* L)
91{ 91{
92 STACK_GROW( L, 1); 92 STACK_GROW( L, 1);
93 STACK_CHECK_START_REL(L, 1); // a 93 STACK_CHECK_START_REL(L, 1); // a
94 DEEP_LOOKUP_KEY.pushValue(L); // a {} 94 kDeepLookupRegKey.pushValue(L); // a {}
95 if (!lua_isnil( L, -1)) 95 if (!lua_isnil( L, -1))
96 { 96 {
97 lua_insert( L, -2); // {} a 97 lua_insert( L, -2); // {} a
@@ -194,7 +194,7 @@ void DeepFactory::DeleteDeepObject(lua_State* L, DeepPrelude* o_)
194char const* DeepFactory::PushDeepProxy(DestState 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, kDeepProxyCacheRegKey, "v"); // DPC
198 lua_pushlightuserdata(L, prelude); // DPC deep 198 lua_pushlightuserdata(L, prelude); // DPC deep
199 lua_rawget(L, -2); // DPC proxy 199 lua_rawget(L, -2); // DPC proxy
200 if (!lua_isnil(L, -1)) 200 if (!lua_isnil(L, -1))
@@ -354,11 +354,11 @@ int DeepFactory::pushDeepUserdata(DestState L, int nuv_) const
354 return luaL_error( L, "DeepFactory::newDeepObjectInternal failed to create deep userdata (out of memory)"); 354 return luaL_error( L, "DeepFactory::newDeepObjectInternal failed to create deep userdata (out of memory)");
355 } 355 }
356 356
357 if (prelude->m_magic != DEEP_VERSION) 357 if (prelude->m_magic != kDeepVersion)
358 { 358 {
359 // just in case, don't leak the newly allocated deep userdata object 359 // just in case, don't leak the newly allocated deep userdata object
360 deleteDeepObjectInternal(L, prelude); 360 deleteDeepObjectInternal(L, prelude);
361 return luaL_error( L, "Bad Deep Factory: DEEP_VERSION is incorrect, rebuild your implementation with the latest deep implementation"); 361 return luaL_error( L, "Bad Deep Factory: kDeepVersion is incorrect, rebuild your implementation with the latest deep implementation");
362 } 362 }
363 363
364 LUA_ASSERT(L, prelude->m_refcount.load(std::memory_order_relaxed) == 0); // 'DeepFactory::PushDeepProxy' will lift it to 1 364 LUA_ASSERT(L, prelude->m_refcount.load(std::memory_order_relaxed) == 0); // 'DeepFactory::PushDeepProxy' will lift it to 1
diff --git a/src/deep.h b/src/deep.h
index 28069fe..673e93a 100644
--- a/src/deep.h
+++ b/src/deep.h
@@ -30,14 +30,14 @@ enum class LookupMode
30 30
31// ################################################################################################# 31// #################################################################################################
32 32
33// xxh64 of string "DEEP_VERSION_3" generated at https://www.pelock.com/products/hash-calculator 33// xxh64 of string "kDeepVersion_1" generated at https://www.pelock.com/products/hash-calculator
34static constexpr UniqueKey DEEP_VERSION{ 0xB2CC0FD9C0AE9674ull, "DEEP_VERSION_3" }; 34static constexpr UniqueKey kDeepVersion{ 0x91171AEC6641E9DBull, "kDeepVersion" };
35 35
36// should be used as header for deep userdata 36// should be used as header for deep userdata
37// a deep userdata is a full userdata that stores a single pointer to the actual DeepPrelude-derived object 37// a deep userdata is a full userdata that stores a single pointer to the actual DeepPrelude-derived object
38struct DeepPrelude 38struct DeepPrelude
39{ 39{
40 UniqueKey const m_magic{ DEEP_VERSION }; 40 UniqueKey const m_magic{ kDeepVersion };
41 // when stored in a keeper state, the full userdata doesn't have a metatable, so we need direct access to the factory 41 // when stored in a keeper state, the full userdata doesn't have a metatable, so we need direct access to the factory
42 class DeepFactory& m_factory; 42 class DeepFactory& m_factory;
43 // data is destroyed when refcount is 0 43 // data is destroyed when refcount is 0
diff --git a/src/keeper.cpp b/src/keeper.cpp
index c306d58..682d70d 100644
--- a/src/keeper.cpp
+++ b/src/keeper.cpp
@@ -73,7 +73,7 @@ class keeper_fifo
73 } 73 }
74}; 74};
75 75
76static constexpr int CONTENTS_TABLE{ 1 }; 76static constexpr int kContentsTableIndex{ 1 };
77 77
78// ################################################################################################# 78// #################################################################################################
79 79
@@ -86,7 +86,7 @@ static constexpr int CONTENTS_TABLE{ 1 };
86 idx_ = lua_absindex(L, idx_); 86 idx_ = lua_absindex(L, idx_);
87 STACK_GROW(L, 1); 87 STACK_GROW(L, 1);
88 // we can replace the fifo userdata in the stack without fear of it being GCed, there are other references around 88 // we can replace the fifo userdata in the stack without fear of it being GCed, there are other references around
89 lua_getiuservalue(L, idx_, CONTENTS_TABLE); 89 lua_getiuservalue(L, idx_, kContentsTableIndex);
90 lua_replace(L, idx_); 90 lua_replace(L, idx_);
91 } 91 }
92 return fifo; 92 return fifo;
@@ -103,7 +103,7 @@ static constexpr int CONTENTS_TABLE{ 1 };
103 keeper_fifo* const fifo{ new (L) keeper_fifo{} }; 103 keeper_fifo* const fifo{ new (L) keeper_fifo{} };
104 STACK_CHECK(L, 1); 104 STACK_CHECK(L, 1);
105 lua_newtable(L); 105 lua_newtable(L);
106 lua_setiuservalue(L, -2, CONTENTS_TABLE); 106 lua_setiuservalue(L, -2, kContentsTableIndex);
107 STACK_CHECK(L, 1); 107 STACK_CHECK(L, 1);
108 return fifo; 108 return fifo;
109} 109}
@@ -182,14 +182,14 @@ static void fifo_pop( lua_State* L, keeper_fifo* fifo_, int count_)
182 182
183// in: linda_ud expected at stack slot idx 183// in: linda_ud expected at stack slot idx
184// out: fifos[ud] 184// out: fifos[ud]
185// crc64/we of string "FIFOS_KEY" generated at http://www.nitrxgen.net/hashgen/ 185// xxh64 of string "kFifosRegKey" generated at https://www.pelock.com/products/hash-calculator
186static constexpr RegistryUniqueKey FIFOS_KEY{ 0xDCE50BBC351CD465ull }; 186static constexpr RegistryUniqueKey kFifosRegKey{ 0x37F11CE5A6D191AAull };
187static void push_table(lua_State* L, int idx_) 187static void push_table(lua_State* L, int idx_)
188{ 188{
189 STACK_GROW(L, 5); 189 STACK_GROW(L, 5);
190 STACK_CHECK_START_REL(L, 0); 190 STACK_CHECK_START_REL(L, 0);
191 idx_ = lua_absindex(L, idx_); 191 idx_ = lua_absindex(L, idx_);
192 FIFOS_KEY.pushValue(L); // ud fifos 192 kFifosRegKey.pushValue(L); // ud fifos
193 lua_pushvalue(L, idx_); // ud fifos ud 193 lua_pushvalue(L, idx_); // ud fifos ud
194 lua_rawget(L, -2); // ud fifos fifos[ud] 194 lua_rawget(L, -2); // ud fifos fifos[ud]
195 STACK_CHECK(L, 2); 195 STACK_CHECK(L, 2);
@@ -217,7 +217,7 @@ int keeper_push_linda_storage(Linda& linda_, DestState L)
217 return 0; 217 return 0;
218 STACK_GROW(KL, 4); // KEEPER MAIN 218 STACK_GROW(KL, 4); // KEEPER MAIN
219 STACK_CHECK_START_REL(KL, 0); 219 STACK_CHECK_START_REL(KL, 0);
220 FIFOS_KEY.pushValue(KL); // fifos 220 kFifosRegKey.pushValue(KL); // fifos
221 lua_pushlightuserdata(KL, &linda_); // fifos ud 221 lua_pushlightuserdata(KL, &linda_); // fifos ud
222 lua_rawget(KL, -2); // fifos storage 222 lua_rawget(KL, -2); // fifos storage
223 lua_remove(KL, -2); // storage 223 lua_remove(KL, -2); // storage
@@ -267,7 +267,7 @@ int keepercall_clear(lua_State* L)
267{ 267{
268 STACK_GROW(L, 3); 268 STACK_GROW(L, 3);
269 STACK_CHECK_START_REL(L, 0); 269 STACK_CHECK_START_REL(L, 0);
270 FIFOS_KEY.pushValue(L); // ud fifos 270 kFifosRegKey.pushValue(L); // ud fifos
271 lua_pushvalue(L, 1); // ud fifos ud 271 lua_pushvalue(L, 1); // ud fifos ud
272 lua_pushnil(L); // ud fifos ud nil 272 lua_pushnil(L); // ud fifos ud nil
273 lua_rawset(L, -3); // ud fifos 273 lua_rawset(L, -3); // ud fifos
@@ -428,31 +428,31 @@ int keepercall_set(lua_State* L)
428 STACK_GROW(L, 6); 428 STACK_GROW(L, 6);
429 429
430 // retrieve fifos associated with the linda 430 // retrieve fifos associated with the linda
431 push_table(L, 1); // ud key [val [, ...]] fifos 431 push_table(L, 1); // ud key [val [, ...]] fifos
432 lua_replace(L, 1); // fifos key [val [, ...]] 432 lua_replace(L, 1); // fifos key [val [, ...]]
433 433
434 // make sure we have a value on the stack 434 // make sure we have a value on the stack
435 if (lua_gettop(L) == 2) // fifos key 435 if (lua_gettop(L) == 2) // fifos key
436 { 436 {
437 lua_pushvalue(L, -1); // fifos key key 437 lua_pushvalue(L, -1); // fifos key key
438 lua_rawget(L, 1); // fifos key fifo|nil 438 lua_rawget(L, 1); // fifos key fifo|nil
439 // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged! 439 // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged!
440 keeper_fifo* const fifo{ keeper_fifo::getPtr(L, -1) }; 440 keeper_fifo* const fifo{ keeper_fifo::getPtr(L, -1) };
441 if (fifo != nullptr) // might be nullptr if we set a nonexistent key to nil 441 if (fifo != nullptr) // might be nullptr if we set a nonexistent key to nil
442 { // fifos key fifo 442 { // fifos key fifo
443 if (fifo->limit < 0) // fifo limit value is the default (unlimited): we can totally remove it 443 if (fifo->limit < 0) // fifo limit value is the default (unlimited): we can totally remove it
444 { 444 {
445 lua_pop(L, 1); // fifos key 445 lua_pop(L, 1); // fifos key
446 lua_pushnil(L); // fifos key nil 446 lua_pushnil(L); // fifos key nil
447 lua_rawset(L, -3); // fifos 447 lua_rawset(L, -3); // fifos
448 } 448 }
449 else 449 else
450 { 450 {
451 // we create room if the fifo was full but it is no longer the case 451 // we create room if the fifo was full but it is no longer the case
452 should_wake_writers = (fifo->limit > 0) && (fifo->count >= fifo->limit); 452 should_wake_writers = (fifo->limit > 0) && (fifo->count >= fifo->limit);
453 lua_remove(L, -2); // fifos fifo 453 lua_remove(L, -2); // fifos fifo
454 lua_newtable(L); // fifos fifo {} 454 lua_newtable(L); // fifos fifo {}
455 lua_setiuservalue(L, -2, CONTENTS_TABLE); // fifos fifo 455 lua_setiuservalue(L, -2, kContentsTableIndex); // fifos fifo
456 fifo->first = 1; 456 fifo->first = 1;
457 fifo->count = 0; 457 fifo->count = 0;
458 } 458 }
@@ -461,32 +461,32 @@ int keepercall_set(lua_State* L)
461 else // set/replace contents stored at the specified key? 461 else // set/replace contents stored at the specified key?
462 { 462 {
463 int const count{ lua_gettop(L) - 2 }; // number of items we want to store 463 int const count{ lua_gettop(L) - 2 }; // number of items we want to store
464 lua_pushvalue(L, 2); // fifos key [val [, ...]] key 464 lua_pushvalue(L, 2); // fifos key [val [, ...]] key
465 lua_rawget(L, 1); // fifos key [val [, ...]] fifo|nil 465 lua_rawget(L, 1); // fifos key [val [, ...]] fifo|nil
466 keeper_fifo* fifo{ keeper_fifo::getPtr(L, -1) }; 466 keeper_fifo* fifo{ keeper_fifo::getPtr(L, -1) };
467 if (fifo == nullptr) // can be nullptr if we store a value at a new key 467 if (fifo == nullptr) // can be nullptr if we store a value at a new key
468 { // fifos key [val [, ...]] nil 468 { // fifos key [val [, ...]] nil
469 // no need to wake writers in that case, because a writer can't wait on an inexistent key 469 // no need to wake writers in that case, because a writer can't wait on an inexistent key
470 lua_pop(L, 1); // fifos key [val [, ...]] 470 lua_pop(L, 1); // fifos key [val [, ...]]
471 std::ignore = fifo_new(KeeperState{ L }); // fifos key [val [, ...]] fifo 471 std::ignore = fifo_new(KeeperState{ L }); // fifos key [val [, ...]] fifo
472 lua_pushvalue(L, 2); // fifos key [val [, ...]] fifo key 472 lua_pushvalue(L, 2); // fifos key [val [, ...]] fifo key
473 lua_pushvalue(L, -2); // fifos key [val [, ...]] fifo key fifo 473 lua_pushvalue(L, -2); // fifos key [val [, ...]] fifo key fifo
474 lua_rawset(L, 1); // fifos key [val [, ...]] fifo 474 lua_rawset(L, 1); // fifos key [val [, ...]] fifo
475 } 475 }
476 else // the fifo exists, we just want to update its contents 476 else // the fifo exists, we just want to update its contents
477 { // fifos key [val [, ...]] fifo 477 { // fifos key [val [, ...]] fifo
478 // we create room if the fifo was full but it is no longer the case 478 // we create room if the fifo was full but it is no longer the case
479 should_wake_writers = (fifo->limit > 0) && (fifo->count >= fifo->limit) && (count < fifo->limit); 479 should_wake_writers = (fifo->limit > 0) && (fifo->count >= fifo->limit) && (count < fifo->limit);
480 // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged! 480 // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged!
481 lua_newtable(L); // fifos key [val [, ...]] fifo {} 481 lua_newtable(L); // fifos key [val [, ...]] fifo {}
482 lua_setiuservalue(L, -2, CONTENTS_TABLE); // fifos key [val [, ...]] fifo 482 lua_setiuservalue(L, -2, kContentsTableIndex); // fifos key [val [, ...]] fifo
483 fifo->first = 1; 483 fifo->first = 1;
484 fifo->count = 0; 484 fifo->count = 0;
485 } 485 }
486 fifo = prepare_fifo_access(L, -1); // fifos key [val [, ...]] fifotbl 486 fifo = prepare_fifo_access(L, -1); // fifos key [val [, ...]] fifotbl
487 // move the fifo below the values we want to store 487 // move the fifo below the values we want to store
488 lua_insert(L, 3); // fifos key fifotbl [val [, ...]] 488 lua_insert(L, 3); // fifos key fifotbl [val [, ...]]
489 fifo_push(L, fifo, count); // fifos key fifotbl 489 fifo_push(L, fifo, count); // fifos key fifotbl
490 } 490 }
491 return should_wake_writers ? (lua_pushboolean(L, 1), 1) : 0; 491 return should_wake_writers ? (lua_pushboolean(L, 1), 1) : 0;
492} 492}
@@ -742,7 +742,7 @@ void init_keepers(Universe* U, lua_State* L)
742 lua_pushfstring(K, "Keeper #%d", i + 1); // "Keeper #n" 742 lua_pushfstring(K, "Keeper #%d", i + 1); // "Keeper #n"
743 lua_setglobal(K, "decoda_name"); // 743 lua_setglobal(K, "decoda_name"); //
744 // create the fifos table in the keeper state 744 // create the fifos table in the keeper state
745 FIFOS_KEY.setValue(K, [](lua_State* L) { lua_newtable(L); }); 745 kFifosRegKey.setValue(K, [](lua_State* L) { lua_newtable(L); });
746 STACK_CHECK(K, 0); 746 STACK_CHECK(K, 0);
747 } 747 }
748 STACK_CHECK(L, 0); 748 STACK_CHECK(L, 0);
@@ -785,13 +785,13 @@ void keeper_toggle_nil_sentinels(lua_State* L, int val_i_, LookupMode const mode
785 { 785 {
786 if (lua_isnil(L, i)) 786 if (lua_isnil(L, i))
787 { 787 {
788 NIL_SENTINEL.pushKey(L); 788 kNilSentinel.pushKey(L);
789 lua_replace(L, i); 789 lua_replace(L, i);
790 } 790 }
791 } 791 }
792 else 792 else
793 { 793 {
794 if (NIL_SENTINEL.equals(L, i)) 794 if (kNilSentinel.equals(L, i))
795 { 795 {
796 lua_pushnil(L); 796 lua_pushnil(L);
797 lua_replace(L, i); 797 lua_replace(L, i);
diff --git a/src/keeper.h b/src/keeper.h
index 4c79fd7..27a4cff 100644
--- a/src/keeper.h
+++ b/src/keeper.h
@@ -35,8 +35,8 @@ struct Keepers
35 Keeper keeper_array[1]; 35 Keeper keeper_array[1];
36}; 36};
37 37
38// crc64/we of string "NIL_SENTINEL" generated at http://www.nitrxgen.net/hashgen/ 38// xxh64 of string "kNilSentinel" generated at https://www.pelock.com/products/hash-calculator
39static constexpr UniqueKey NIL_SENTINEL{ 0x7EAAFA003A1D11A1ull, "linda.null" }; 39static constexpr UniqueKey kNilSentinel{ 0xC457D4EDDB05B5E4ull, "lanes.null" };
40 40
41void init_keepers(Universe* U, lua_State* L); 41void init_keepers(Universe* U, lua_State* L);
42void close_keepers(Universe* U); 42void close_keepers(Universe* U);
diff --git a/src/lanes.cpp b/src/lanes.cpp
index d549449..1a4e8b7 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -189,7 +189,7 @@ static void lane_main(Lane* lane);
189void Lane::startThread(int priority_) 189void Lane::startThread(int priority_)
190{ 190{
191 m_thread = std::jthread([this]() { lane_main(this); }); 191 m_thread = std::jthread([this]() { lane_main(this); });
192 if (priority_ != THREAD_PRIO_DEFAULT) 192 if (priority_ != kThreadPrioDefault)
193 { 193 {
194 JTHREAD_SET_PRIORITY(m_thread, priority_, U->m_sudo); 194 JTHREAD_SET_PRIORITY(m_thread, priority_, U->m_sudo);
195 } 195 }
@@ -218,8 +218,8 @@ static void securize_debug_threadname(lua_State* L, Lane* lane_)
218 218
219#if ERROR_FULL_STACK 219#if ERROR_FULL_STACK
220[[nodiscard]] static int lane_error(lua_State* L); 220[[nodiscard]] static int lane_error(lua_State* L);
221// crc64/we of string "STACKTRACE_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 221// xxh64 of string "kStackTraceRegKey" generated at https://www.pelock.com/products/hash-calculator
222static constexpr RegistryUniqueKey STACKTRACE_REGKEY{ 0x534AF7D3226A429Full }; 222static constexpr RegistryUniqueKey kStackTraceRegKey{ 0x3F327747CACAA904ull };
223#endif // ERROR_FULL_STACK 223#endif // ERROR_FULL_STACK
224 224
225/* 225/*
@@ -230,8 +230,8 @@ static constexpr RegistryUniqueKey STACKTRACE_REGKEY{ 0x534AF7D3226A429Full };
230* error (and maybe stack trace) parameters to the finalizer functions would 230* error (and maybe stack trace) parameters to the finalizer functions would
231* anyways complicate that approach. 231* anyways complicate that approach.
232*/ 232*/
233// crc64/we of string "FINALIZER_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 233// xxh64 of string "kFinalizerRegKey" generated at https://www.pelock.com/products/hash-calculator
234static constexpr RegistryUniqueKey FINALIZER_REGKEY{ 0x188FCCB8BF348E09ull }; 234static constexpr RegistryUniqueKey kFinalizerRegKey{ 0xFE936BFAA718FEEAull };
235 235
236// ################################################################################################# 236// #################################################################################################
237 237
@@ -260,13 +260,13 @@ static void push_finalizers_table(lua_State* L)
260 STACK_GROW(L, 3); 260 STACK_GROW(L, 3);
261 STACK_CHECK_START_REL(L, 0); 261 STACK_CHECK_START_REL(L, 0);
262 262
263 FINALIZER_REGKEY.pushValue(L); // ? 263 kFinalizerRegKey.pushValue(L); // ?
264 if (lua_isnil(L, -1)) // nil? 264 if (lua_isnil(L, -1)) // nil?
265 { 265 {
266 lua_pop(L, 1); // 266 lua_pop(L, 1); //
267 // store a newly created table in the registry, but leave it on the stack too 267 // store a newly created table in the registry, but leave it on the stack too
268 lua_newtable(L); // t 268 lua_newtable(L); // t
269 FINALIZER_REGKEY.setValue(L, [](lua_State* L) { lua_pushvalue(L, -2); }); // t 269 kFinalizerRegKey.setValue(L, [](lua_State* L) { lua_pushvalue(L, -2); }); // t
270 } 270 }
271 STACK_CHECK(L, 1); 271 STACK_CHECK(L, 1);
272} 272}
@@ -312,12 +312,12 @@ static void push_stack_trace(lua_State* L, int rc_, int stk_base_)
312 // fetch the call stack table from the registry where the handler stored it 312 // fetch the call stack table from the registry where the handler stored it
313 STACK_GROW(L, 1); 313 STACK_GROW(L, 1);
314 // yields nil if no stack was generated (in case of cancellation for example) 314 // yields nil if no stack was generated (in case of cancellation for example)
315 STACKTRACE_REGKEY.pushValue(L); // err trace|nil 315 kStackTraceRegKey.pushValue(L); // err trace|nil
316 STACK_CHECK(L, 1); 316 STACK_CHECK(L, 1);
317 317
318 // For cancellation the error message is CANCEL_ERROR, and a stack trace isn't placed 318 // For cancellation the error message is kCancelError, and a stack trace isn't placed
319 // For other errors, the message can be whatever was thrown, and we should have a stack trace table 319 // For other errors, the message can be whatever was thrown, and we should have a stack trace table
320 LUA_ASSERT(L, lua_type(L, 1 + stk_base_) == (CANCEL_ERROR.equals(L, stk_base_) ? LUA_TNIL : LUA_TTABLE)); 320 LUA_ASSERT(L, lua_type(L, 1 + stk_base_) == (kCancelError.equals(L, stk_base_) ? LUA_TNIL : LUA_TTABLE));
321 // Just leaving the stack trace table on the stack is enough to get it through to the master. 321 // Just leaving the stack trace table on the stack is enough to get it through to the master.
322 break; 322 break;
323 } 323 }
@@ -326,8 +326,8 @@ static void push_stack_trace(lua_State* L, int rc_, int stk_base_)
326 case LUA_ERRMEM: // memory allocation error (handler not called) 326 case LUA_ERRMEM: // memory allocation error (handler not called)
327 case LUA_ERRERR: // error while running the error handler (if any, for example an out-of-memory condition) 327 case LUA_ERRERR: // error while running the error handler (if any, for example an out-of-memory condition)
328 default: 328 default:
329 // we should have a single value which is either a string (the error message) or CANCEL_ERROR 329 // we should have a single value which is either a string (the error message) or kCancelError
330 LUA_ASSERT(L, (lua_gettop(L) == stk_base_) && ((lua_type(L, stk_base_) == LUA_TSTRING) || CANCEL_ERROR.equals(L, stk_base_))); 330 LUA_ASSERT(L, (lua_gettop(L) == stk_base_) && ((lua_type(L, stk_base_) == LUA_TSTRING) || kCancelError.equals(L, stk_base_)));
331 break; 331 break;
332 } 332 }
333} 333}
@@ -349,7 +349,7 @@ static void push_stack_trace(lua_State* L, int rc_, int stk_base_)
349 349
350[[nodiscard]] static int run_finalizers(lua_State* L, int lua_rc_) 350[[nodiscard]] static int run_finalizers(lua_State* L, int lua_rc_)
351{ 351{
352 FINALIZER_REGKEY.pushValue(L); // ... finalizers? 352 kFinalizerRegKey.pushValue(L); // ... finalizers?
353 if (lua_isnil(L, -1)) 353 if (lua_isnil(L, -1))
354 { 354 {
355 lua_pop(L, 1); 355 lua_pop(L, 1);
@@ -373,7 +373,7 @@ static void push_stack_trace(lua_State* L, int rc_, int stk_base_)
373 LUA_ASSERT(L, finalizers_index == 2 || finalizers_index == 3); 373 LUA_ASSERT(L, finalizers_index == 2 || finalizers_index == 3);
374 //char const* err_msg = lua_tostring(L, 1); 374 //char const* err_msg = lua_tostring(L, 1);
375 lua_pushvalue(L, 1); // ... finalizers lane_error finalizer err_msg 375 lua_pushvalue(L, 1); // ... finalizers lane_error finalizer err_msg
376 // note we don't always have a stack trace for example when CANCEL_ERROR, or when we got an error that doesn't call our handler, such as LUA_ERRMEM 376 // note we don't always have a stack trace for example when kCancelError, or when we got an error that doesn't call our handler, such as LUA_ERRMEM
377 if (finalizers_index == 3) 377 if (finalizers_index == 3)
378 { 378 {
379 lua_pushvalue(L, 2); // ... finalizers lane_error finalizer err_msg stack_trace 379 lua_pushvalue(L, 2); // ... finalizers lane_error finalizer err_msg stack_trace
@@ -633,8 +633,8 @@ LUAG_FUNC( set_singlethreaded)
633*/ 633*/
634#if ERROR_FULL_STACK 634#if ERROR_FULL_STACK
635 635
636// crc64/we of string "EXTENDED_STACKTRACE_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 636// xxh64 of string "kExtendedStackTraceRegKey" generated at https://www.pelock.com/products/hash-calculator
637static constexpr RegistryUniqueKey EXTENDED_STACKTRACE_REGKEY{ 0x2357C69A7C92C936ull }; // used as registry key 637static constexpr RegistryUniqueKey kExtendedStackTraceRegKey{ 0x38147AD48FB426E2ull }; // used as registry key
638 638
639LUAG_FUNC( set_error_reporting) 639LUAG_FUNC( set_error_reporting)
640{ 640{
@@ -648,7 +648,7 @@ LUAG_FUNC( set_error_reporting)
648 return luaL_error(L, "unsupported error reporting model %s", mode); 648 return luaL_error(L, "unsupported error reporting model %s", mode);
649 } 649 }
650 650
651 EXTENDED_STACKTRACE_REGKEY.setValue(L, [extended](lua_State* L) { lua_pushboolean(L, extended ? 1 : 0); }); 651 kExtendedStackTraceRegKey.setValue(L, [extended](lua_State* L) { lua_pushboolean(L, extended ? 1 : 0); });
652 return 0; 652 return 0;
653} 653}
654 654
@@ -659,16 +659,16 @@ LUAG_FUNC( set_error_reporting)
659 659
660 // Don't do stack survey for cancelled lanes. 660 // Don't do stack survey for cancelled lanes.
661 // 661 //
662 if (CANCEL_ERROR.equals(L, 1)) 662 if (kCancelError.equals(L, 1))
663 { 663 {
664 return 1; // just pass on 664 return 1; // just pass on
665 } 665 }
666 666
667 STACK_GROW(L, 3); 667 STACK_GROW(L, 3);
668 bool const extended{ EXTENDED_STACKTRACE_REGKEY.readBoolValue(L) }; 668 bool const extended{ kExtendedStackTraceRegKey.readBoolValue(L) };
669 STACK_CHECK(L, 1); 669 STACK_CHECK(L, 1);
670 670
671 // Place stack trace at 'registry[STACKTRACE_REGKEY]' for the 'lua_pcall()' 671 // Place stack trace at 'registry[kStackTraceRegKey]' for the 'lua_pcall()'
672 // caller to fetch. This bypasses the Lua 5.1 limitation of only one 672 // caller to fetch. This bypasses the Lua 5.1 limitation of only one
673 // return value from error handler to 'lua_pcall()' caller. 673 // return value from error handler to 'lua_pcall()' caller.
674 674
@@ -719,7 +719,7 @@ LUAG_FUNC( set_error_reporting)
719 } 719 }
720 720
721 // store the stack trace table in the registry 721 // store the stack trace table in the registry
722 STACKTRACE_REGKEY.setValue(L, [](lua_State* L) { lua_insert(L, -2); }); // some_error 722 kStackTraceRegKey.setValue(L, [](lua_State* L) { lua_insert(L, -2); }); // some_error
723 723
724 STACK_CHECK(L, 1); 724 STACK_CHECK(L, 1);
725 return 1; // the untouched error value 725 return 1; // the untouched error value
@@ -767,9 +767,9 @@ LUAG_FUNC(set_thread_priority)
767 // public Lanes API accepts a generic range -3/+3 767 // public Lanes API accepts a generic range -3/+3
768 // that will be remapped into the platform-specific scheduler priority scheme 768 // that will be remapped into the platform-specific scheduler priority scheme
769 // On some platforms, -3 is equivalent to -2 and +3 to +2 769 // On some platforms, -3 is equivalent to -2 and +3 to +2
770 if (prio < THREAD_PRIO_MIN || prio > THREAD_PRIO_MAX) 770 if (prio < kThreadPrioMin || prio > kThreadPrioMax)
771 { 771 {
772 return luaL_error(L, "priority out of range: %d..+%d (%d)", THREAD_PRIO_MIN, THREAD_PRIO_MAX, prio); 772 return luaL_error(L, "priority out of range: %d..+%d (%d)", kThreadPrioMin, kThreadPrioMax, prio);
773 } 773 }
774 THREAD_SET_PRIORITY(static_cast<int>(prio), universe_get(L)->m_sudo); 774 THREAD_SET_PRIORITY(static_cast<int>(prio), universe_get(L)->m_sudo);
775 return 0; 775 return 0;
@@ -870,7 +870,7 @@ static void lane_main(Lane* lane)
870 // in case of error and if it exists, fetch stack trace from registry and push it 870 // in case of error and if it exists, fetch stack trace from registry and push it
871 push_stack_trace(L, rc, 1); // retvals|error [trace] 871 push_stack_trace(L, rc, 1); // retvals|error [trace]
872 872
873 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "Lane %p body: %s (%s)\n" INDENT_END, L, get_errcode_name(rc), CANCEL_ERROR.equals(L, 1) ? "cancelled" : lua_typename(L, lua_type(L, 1)))); 873 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "Lane %p body: %s (%s)\n" INDENT_END, L, get_errcode_name(rc), kCancelError.equals(L, 1) ? "cancelled" : lua_typename(L, lua_type(L, 1))));
874 // Call finalizers, if the script has set them up. 874 // Call finalizers, if the script has set them up.
875 // 875 //
876 int rc2{ run_finalizers(L, rc) }; 876 int rc2{ run_finalizers(L, rc) };
@@ -901,7 +901,7 @@ static void lane_main(Lane* lane)
901 { 901 {
902 // leave results (1..top) or error message + stack trace (1..2) on the stack - master will copy them 902 // leave results (1..top) or error message + stack trace (1..2) on the stack - master will copy them
903 903
904 Lane::Status st = (rc == LUA_OK) ? Lane::Done : CANCEL_ERROR.equals(L, 1) ? Lane::Cancelled : Lane::Error; 904 Lane::Status st = (rc == LUA_OK) ? Lane::Done : kCancelError.equals(L, 1) ? Lane::Cancelled : Lane::Error;
905 905
906 { 906 {
907 // 'm_done_mutex' protects the -> Done|Error|Cancelled state change 907 // 'm_done_mutex' protects the -> Done|Error|Cancelled state change
@@ -959,8 +959,8 @@ LUAG_FUNC(register)
959 959
960// ################################################################################################# 960// #################################################################################################
961 961
962// crc64/we of string "GCCB_KEY" generated at http://www.nitrxgen.net/hashgen/ 962// xxh64 of string "kLaneGC" generated at https://www.pelock.com/products/hash-calculator
963static constexpr UniqueKey GCCB_KEY{ 0xCFB1F046EF074E88ull }; 963static constexpr UniqueKey kLaneGC{ 0x5D6122141727F960ull };
964 964
965//--- 965//---
966// lane_ud = lane_new( function 966// lane_ud = lane_new( function
@@ -978,23 +978,23 @@ LUAG_FUNC(lane_new)
978{ 978{
979 char const* const libs_str{ lua_tostring(L, 2) }; 979 char const* const libs_str{ lua_tostring(L, 2) };
980 bool const have_priority{ !lua_isnoneornil(L, 3) }; 980 bool const have_priority{ !lua_isnoneornil(L, 3) };
981 int const priority{ have_priority ? (int) lua_tointeger(L, 3) : THREAD_PRIO_DEFAULT }; 981 int const priority{ have_priority ? (int) lua_tointeger(L, 3) : kThreadPrioDefault };
982 int const globals_idx{ lua_isnoneornil(L, 4) ? 0 : 4 }; 982 int const globals_idx{ lua_isnoneornil(L, 4) ? 0 : 4 };
983 int const package_idx{ lua_isnoneornil(L, 5) ? 0 : 5 }; 983 int const package_idx{ lua_isnoneornil(L, 5) ? 0 : 5 };
984 int const required_idx{ lua_isnoneornil(L, 6) ? 0 : 6 }; 984 int const required_idx{ lua_isnoneornil(L, 6) ? 0 : 6 };
985 int const gc_cb_idx{ lua_isnoneornil(L, 7) ? 0 : 7 }; 985 int const gc_cb_idx{ lua_isnoneornil(L, 7) ? 0 : 7 };
986 986
987 static constexpr int FIXED_ARGS{ 7 }; 987 static constexpr int kFixedArgsIdx{ 7 };
988 int const nargs{ lua_gettop(L) - FIXED_ARGS }; 988 int const nargs{ lua_gettop(L) - kFixedArgsIdx };
989 Universe* const U{ universe_get(L) }; 989 Universe* const U{ universe_get(L) };
990 LUA_ASSERT(L, nargs >= 0); 990 LUA_ASSERT(L, nargs >= 0);
991 991
992 // public Lanes API accepts a generic range -3/+3 992 // public Lanes API accepts a generic range -3/+3
993 // that will be remapped into the platform-specific scheduler priority scheme 993 // that will be remapped into the platform-specific scheduler priority scheme
994 // On some platforms, -3 is equivalent to -2 and +3 to +2 994 // On some platforms, -3 is equivalent to -2 and +3 to +2
995 if (have_priority && (priority < THREAD_PRIO_MIN || priority > THREAD_PRIO_MAX)) 995 if (have_priority && (priority < kThreadPrioMin || priority > kThreadPrioMax))
996 { 996 {
997 return luaL_error(L, "Priority out of range: %d..+%d (%d)", THREAD_PRIO_MIN, THREAD_PRIO_MAX, priority); 997 return luaL_error(L, "Priority out of range: %d..+%d (%d)", kThreadPrioMin, kThreadPrioMax, priority);
998 } 998 }
999 999
1000 /* --- Create and prepare the sub state --- */ 1000 /* --- Create and prepare the sub state --- */
@@ -1039,7 +1039,7 @@ LUAG_FUNC(lane_new)
1039 prepareUserData(); 1039 prepareUserData();
1040 // leave a single cancel_error on the stack for the caller 1040 // leave a single cancel_error on the stack for the caller
1041 lua_settop(m_lane->L, 0); 1041 lua_settop(m_lane->L, 0);
1042 CANCEL_ERROR.pushKey(m_lane->L); 1042 kCancelError.pushKey(m_lane->L);
1043 { 1043 {
1044 std::lock_guard lock{ m_lane->m_done_mutex }; 1044 std::lock_guard lock{ m_lane->m_done_mutex };
1045 m_lane->m_status = Lane::Cancelled; 1045 m_lane->m_status = Lane::Cancelled;
@@ -1073,7 +1073,7 @@ LUAG_FUNC(lane_new)
1073 // Store the gc_cb callback in the uservalue 1073 // Store the gc_cb callback in the uservalue
1074 if (m_gc_cb_idx > 0) 1074 if (m_gc_cb_idx > 0)
1075 { 1075 {
1076 GCCB_KEY.pushKey(m_L); // ... lane uv k 1076 kLaneGC.pushKey(m_L); // ... lane uv k
1077 lua_pushvalue(m_L, m_gc_cb_idx); // ... lane uv k gc_cb 1077 lua_pushvalue(m_L, m_gc_cb_idx); // ... lane uv k gc_cb
1078 lua_rawset(m_L, -3); // ... lane uv 1078 lua_rawset(m_L, -3); // ... lane uv
1079 } 1079 }
@@ -1243,10 +1243,10 @@ LUAG_FUNC(lane_new)
1243 } 1243 }
1244 } 1244 }
1245 STACK_CHECK(L, -nargs); 1245 STACK_CHECK(L, -nargs);
1246 LUA_ASSERT(L, lua_gettop( L) == FIXED_ARGS); 1246 LUA_ASSERT(L, lua_gettop(L) == kFixedArgsIdx);
1247 1247
1248 // Store 'lane' in the lane's registry, for 'cancel_test()' (we do cancel tests at pending send/receive). 1248 // Store 'lane' in the lane's registry, for 'cancel_test()' (we do cancel tests at pending send/receive).
1249 LANE_POINTER_REGKEY.setValue(L2, [lane](lua_State* L) { lua_pushlightuserdata(L, lane); }); // func [... args ...] 1249 kLanePointerRegKey.setValue(L2, [lane](lua_State* L_) { lua_pushlightuserdata(L_, lane); }); // func [... args ...]
1250 STACK_CHECK(L2, 1 + nargs); 1250 STACK_CHECK(L2, 1 + nargs);
1251 1251
1252 STACK_CHECK_RESET_REL(L, 0); 1252 STACK_CHECK_RESET_REL(L, 0);
@@ -1278,7 +1278,7 @@ LUAG_FUNC(lane_new)
1278 1278
1279 // if there a gc callback? 1279 // if there a gc callback?
1280 lua_getiuservalue(L, 1, 1); // ud uservalue 1280 lua_getiuservalue(L, 1, 1); // ud uservalue
1281 GCCB_KEY.pushKey(L); // ud uservalue __gc 1281 kLaneGC.pushKey(L); // ud uservalue __gc
1282 lua_rawget(L, -2); // ud uservalue gc_cb|nil 1282 lua_rawget(L, -2); // ud uservalue gc_cb|nil
1283 if (!lua_isnil(L, -1)) 1283 if (!lua_isnil(L, -1))
1284 { 1284 {
@@ -1441,9 +1441,9 @@ LUAG_FUNC(thread_join)
1441 return ret; 1441 return ret;
1442} 1442}
1443 1443
1444// #################################################################################################
1444 1445
1445//--- 1446// lane:__index(key,usr) -> value
1446// thread_index( ud, key) -> value
1447// 1447//
1448// If key is found in the environment, return it 1448// If key is found in the environment, return it
1449// If key is numeric, wait until the thread returns and populate the environment with the return values 1449// If key is numeric, wait until the thread returns and populate the environment with the return values
@@ -1452,44 +1452,43 @@ LUAG_FUNC(thread_join)
1452// Else raise an error 1452// Else raise an error
1453LUAG_FUNC(thread_index) 1453LUAG_FUNC(thread_index)
1454{ 1454{
1455 static constexpr int UD{ 1 }; 1455 static constexpr int kSelf{ 1 };
1456 static constexpr int KEY{ 2 }; 1456 static constexpr int kKey{ 2 };
1457 static constexpr int USR{ 3 }; 1457 Lane* const lane{ ToLane(L, kSelf) };
1458 Lane* const lane{ ToLane(L, UD) };
1459 LUA_ASSERT(L, lua_gettop(L) == 2); 1458 LUA_ASSERT(L, lua_gettop(L) == 2);
1460 1459
1461 STACK_GROW(L, 8); // up to 8 positions are needed in case of error propagation 1460 STACK_GROW(L, 8); // up to 8 positions are needed in case of error propagation
1462 1461
1463 // If key is numeric, wait until the thread returns and populate the environment with the return values 1462 // If key is numeric, wait until the thread returns and populate the environment with the return values
1464 if (lua_type(L, KEY) == LUA_TNUMBER) 1463 if (lua_type(L, kKey) == LUA_TNUMBER)
1465 { 1464 {
1465 static constexpr int kUsr{ 3 };
1466 // first, check that we don't already have an environment that holds the requested value 1466 // first, check that we don't already have an environment that holds the requested value
1467 { 1467 {
1468 // If key is found in the uservalue, return it 1468 // If key is found in the uservalue, return it
1469 lua_getiuservalue(L, UD, 1); 1469 lua_getiuservalue(L, kSelf, 1);
1470 lua_pushvalue(L, KEY); 1470 lua_pushvalue(L, kKey);
1471 lua_rawget(L, USR); 1471 lua_rawget(L, kUsr);
1472 if (!lua_isnil(L, -1)) 1472 if (!lua_isnil(L, -1))
1473 { 1473 {
1474 return 1; 1474 return 1;
1475 } 1475 }
1476 lua_pop(L, 1); 1476 lua_pop(L, 1);
1477 } 1477 }
1478 { 1478 {
1479 // check if we already fetched the values from the thread or not 1479 // check if we already fetched the values from the thread or not
1480 lua_Integer key = lua_tointeger(L, KEY);
1481 lua_pushinteger(L, 0); 1480 lua_pushinteger(L, 0);
1482 lua_rawget(L, USR); 1481 lua_rawget(L, kUsr);
1483 bool const fetched{ !lua_isnil(L, -1) }; 1482 bool const fetched{ !lua_isnil(L, -1) };
1484 lua_pop(L, 1); // back to our 2 args + uservalue on the stack 1483 lua_pop(L, 1); // back to our 2 args + uservalue on the stack
1485 if (!fetched) 1484 if (!fetched)
1486 { 1485 {
1487 lua_pushinteger(L, 0); 1486 lua_pushinteger(L, 0);
1488 lua_pushboolean(L, 1); 1487 lua_pushboolean(L, 1);
1489 lua_rawset(L, USR); 1488 lua_rawset(L, kUsr);
1490 // wait until thread has completed 1489 // wait until thread has completed
1491 lua_pushcfunction(L, LG_thread_join); 1490 lua_pushcfunction(L, LG_thread_join);
1492 lua_pushvalue(L, UD); 1491 lua_pushvalue(L, kSelf);
1493 lua_call(L, 1, LUA_MULTRET); // all return values are on the stack, at slots 4+ 1492 lua_call(L, 1, LUA_MULTRET); // all return values are on the stack, at slots 4+
1494 switch (lane->m_status) 1493 switch (lane->m_status)
1495 { 1494 {
@@ -1508,7 +1507,7 @@ LUAG_FUNC(thread_index)
1508 for (int i = nvalues; i > 0; --i) 1507 for (int i = nvalues; i > 0; --i)
1509 { 1508 {
1510 // pop the last element of the stack, to store it in the uservalue at its proper index 1509 // pop the last element of the stack, to store it in the uservalue at its proper index
1511 lua_rawseti(L, USR, i); 1510 lua_rawseti(L, kUsr, i);
1512 } 1511 }
1513 } 1512 }
1514 break; 1513 break;
@@ -1521,7 +1520,7 @@ LUAG_FUNC(thread_index)
1521 // store errstring at key -1 1520 // store errstring at key -1
1522 lua_pushnumber(L, -1); 1521 lua_pushnumber(L, -1);
1523 lua_pushvalue(L, 5); 1522 lua_pushvalue(L, 5);
1524 lua_rawset(L, USR); 1523 lua_rawset(L, kUsr);
1525 break; 1524 break;
1526 1525
1527 case Lane::Cancelled: 1526 case Lane::Cancelled:
@@ -1529,11 +1528,12 @@ LUAG_FUNC(thread_index)
1529 break; 1528 break;
1530 } 1529 }
1531 } 1530 }
1532 lua_settop(L, 3); // UD KEY ENV 1531 lua_settop(L, 3); // self KEY ENV
1532 int const key{ static_cast<int>(lua_tointeger(L, kKey)) };
1533 if (key != -1) 1533 if (key != -1)
1534 { 1534 {
1535 lua_pushnumber(L, -1); // UD KEY ENV -1 1535 lua_pushnumber(L, -1); // self KEY ENV -1
1536 lua_rawget(L, USR); // UD KEY ENV "error" 1536 lua_rawget(L, kUsr); // self KEY ENV "error"|nil
1537 if (!lua_isnil(L, -1)) // an error was stored 1537 if (!lua_isnil(L, -1)) // an error was stored
1538 { 1538 {
1539 // Note: Lua 5.1 interpreter is not prepared to show 1539 // Note: Lua 5.1 interpreter is not prepared to show
@@ -1547,48 +1547,48 @@ LUAG_FUNC(thread_index)
1547 // Level 3 should show the line where 'h[x]' was read 1547 // Level 3 should show the line where 'h[x]' was read
1548 // but this only seems to work for string messages 1548 // but this only seems to work for string messages
1549 // (Lua 5.1.4). No idea, why. --AKa 22-Jan-2009 1549 // (Lua 5.1.4). No idea, why. --AKa 22-Jan-2009
1550 lua_getmetatable(L, UD); // UD KEY ENV "error" mt 1550 lua_getmetatable(L, kSelf); // self KEY ENV "error" mt
1551 lua_getfield(L, -1, "cached_error"); // UD KEY ENV "error" mt error() 1551 lua_getfield(L, -1, "cached_error"); // self KEY ENV "error" mt error()
1552 lua_getfield(L, -2, "cached_tostring"); // UD KEY ENV "error" mt error() tostring() 1552 lua_getfield(L, -2, "cached_tostring"); // self KEY ENV "error" mt error() tostring()
1553 lua_pushvalue(L, 4); // UD KEY ENV "error" mt error() tostring() "error" 1553 lua_pushvalue(L, 4); // self KEY ENV "error" mt error() tostring() "error"
1554 lua_call(L, 1, 1); // tostring( errstring) -- just in case // UD KEY ENV "error" mt error() "error" 1554 lua_call(L, 1, 1); // tostring( errstring) -- just in case // self KEY ENV "error" mt error() "error"
1555 lua_pushinteger(L, 3); // UD KEY ENV "error" mt error() "error" 3 1555 lua_pushinteger(L, 3); // self KEY ENV "error" mt error() "error" 3
1556 lua_call(L, 2, 0); // error( tostring( errstring), 3) // UD KEY ENV "error" mt 1556 lua_call(L, 2, 0); // error( tostring( errstring), 3) // self KEY ENV "error" mt
1557 } 1557 }
1558 else 1558 else
1559 { 1559 {
1560 lua_pop(L, 1); // back to our 3 arguments on the stack 1560 lua_pop(L, 1); // self KEY ENV
1561 } 1561 }
1562 } 1562 }
1563 lua_rawgeti(L, USR, (int)key); 1563 lua_rawgeti(L, kUsr, key);
1564 } 1564 }
1565 return 1; 1565 return 1;
1566 } 1566 }
1567 if (lua_type(L, KEY) == LUA_TSTRING) 1567 if (lua_type(L, kKey) == LUA_TSTRING)
1568 { 1568 {
1569 char const* const keystr{ lua_tostring(L, KEY) }; 1569 char const* const keystr{ lua_tostring(L, kKey) };
1570 lua_settop(L, 2); // keep only our original arguments on the stack 1570 lua_settop(L, 2); // keep only our original arguments on the stack
1571 if (strcmp( keystr, "status") == 0) 1571 if (strcmp( keystr, "status") == 0)
1572 { 1572 {
1573 lane->pushThreadStatus(L); // push the string representing the status 1573 lane->pushThreadStatus(L); // push the string representing the status
1574 return 1; 1574 return 1;
1575 } 1575 }
1576 // return UD.metatable[key] 1576 // return self.metatable[key]
1577 lua_getmetatable(L, UD); // UD KEY mt 1577 lua_getmetatable(L, kSelf); // self KEY mt
1578 lua_replace(L, -3); // mt KEY 1578 lua_replace(L, -3); // mt KEY
1579 lua_rawget(L, -2); // mt value 1579 lua_rawget(L, -2); // mt value
1580 // only "cancel" and "join" are registered as functions, any other string will raise an error 1580 // only "cancel" and "join" are registered as functions, any other string will raise an error
1581 if (lua_iscfunction(L, -1)) 1581 if (!lua_iscfunction(L, -1))
1582 { 1582 {
1583 return 1; 1583 luaL_error(L, "can't index a lane with '%s'", keystr); // doesn't return
1584 } 1584 }
1585 return luaL_error(L, "can't index a lane with '%s'", keystr); 1585 return 1;
1586 } 1586 }
1587 // unknown key 1587 // unknown key
1588 lua_getmetatable(L, UD); 1588 lua_getmetatable(L, kSelf);
1589 lua_getfield(L, -1, "cached_error"); 1589 lua_getfield(L, -1, "cached_error");
1590 lua_pushliteral(L, "Unknown key: "); 1590 lua_pushliteral(L, "Unknown key: ");
1591 lua_pushvalue(L, KEY); 1591 lua_pushvalue(L, kKey);
1592 lua_concat(L, 2); 1592 lua_concat(L, 2);
1593 lua_call(L, 1, 0); // error( "Unknown key: " .. key) -> doesn't return 1593 lua_call(L, 1, 0); // error( "Unknown key: " .. key) -> doesn't return
1594 return 0; 1594 return 0;
@@ -1863,15 +1863,19 @@ LUAG_FUNC(configure)
1863 ); // settings M VERSION 1863 ); // settings M VERSION
1864 lua_setfield(L, -2, "version"); // settings M 1864 lua_setfield(L, -2, "version"); // settings M
1865 1865
1866 lua_pushinteger(L, THREAD_PRIO_MAX); // settings M THREAD_PRIO_MAX 1866 lua_pushinteger(L, kThreadPrioMax); // settings M kThreadPrioMax
1867 lua_setfield(L, -2, "max_prio"); // settings M 1867 lua_setfield(L, -2, "max_prio"); // settings M
1868 1868
1869 CANCEL_ERROR.pushKey(L); // settings M CANCEL_ERROR 1869 kCancelError.pushKey(L); // settings M kCancelError
1870 lua_setfield(L, -2, "cancel_error"); // settings M 1870 lua_setfield(L, -2, "cancel_error"); // settings M
1871 1871
1872 /* to activate in a separate commit
1873 kNilSentinel.pushKey(L); // settings M kNilSentinel
1874 lua_setfield(L, -2, "null"); // settings M
1875 */
1872 STACK_CHECK(L, 2); // reference stack contains only the function argument 'settings' 1876 STACK_CHECK(L, 2); // reference stack contains only the function argument 'settings'
1873 // we'll need this every time we transfer some C function from/to this state 1877 // we'll need this every time we transfer some C function from/to this state
1874 LOOKUP_REGKEY.setValue(L, [](lua_State* L) { lua_newtable(L); }); // settings M 1878 kLookupRegKey.setValue(L, [](lua_State* L) { lua_newtable(L); }); // settings M
1875 STACK_CHECK(L, 2); 1879 STACK_CHECK(L, 2);
1876 1880
1877 // register all native functions found in that module in the transferable functions database 1881 // register all native functions found in that module in the transferable functions database
@@ -1893,8 +1897,8 @@ LUAG_FUNC(configure)
1893 } 1897 }
1894 lua_pop(L, 1); // settings 1898 lua_pop(L, 1); // settings
1895 1899
1896 // set _R[CONFIG_REGKEY] = settings 1900 // set _R[kConfigRegKey] = settings
1897 CONFIG_REGKEY.setValue(L, [](lua_State* L) { lua_pushvalue(L, -2); }); 1901 kConfigRegKey.setValue(L, [](lua_State* L) { lua_pushvalue(L, -2); });
1898 STACK_CHECK(L, 1); 1902 STACK_CHECK(L, 1);
1899 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%p: lanes.configure() END\n" INDENT_END, L)); 1903 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%p: lanes.configure() END\n" INDENT_END, L));
1900 // Return the settings table 1904 // Return the settings table
@@ -1986,7 +1990,7 @@ LANES_API int luaopen_lanes_core( lua_State* L)
1986 lua_pushvalue(L, 1); // M "lanes.core" 1990 lua_pushvalue(L, 1); // M "lanes.core"
1987 lua_pushvalue(L, -2); // M "lanes.core" M 1991 lua_pushvalue(L, -2); // M "lanes.core" M
1988 lua_pushcclosure(L, LG_configure, 2); // M LG_configure() 1992 lua_pushcclosure(L, LG_configure, 2); // M LG_configure()
1989 CONFIG_REGKEY.pushValue(L); // M LG_configure() settings 1993 kConfigRegKey.pushValue(L); // M LG_configure() settings
1990 if (!lua_isnil(L, -1)) // this is not the first require "lanes.core": call configure() immediately 1994 if (!lua_isnil(L, -1)) // this is not the first require "lanes.core": call configure() immediately
1991 { 1995 {
1992 lua_pushvalue(L, -1); // M LG_configure() settings settings 1996 lua_pushvalue(L, -1); // M LG_configure() settings settings
diff --git a/src/lanes_private.h b/src/lanes_private.h
index c35d618..7ecb9a7 100644
--- a/src/lanes_private.h
+++ b/src/lanes_private.h
@@ -92,8 +92,8 @@ class Lane
92 void pushThreadStatus(lua_State* L_); 92 void pushThreadStatus(lua_State* L_);
93}; 93};
94 94
95// xxh64 of string "LANE_POINTER_REGKEY" generated at https://www.pelock.com/products/hash-calculator 95// xxh64 of string "kLanePointerRegKey" generated at https://www.pelock.com/products/hash-calculator
96static constexpr RegistryUniqueKey LANE_POINTER_REGKEY{ 0xB3022205633743BCull }; // used as registry key 96static constexpr RegistryUniqueKey kLanePointerRegKey{ 0x2D8CF03FE9F0A51Aull }; // used as registry key
97 97
98// To allow free-running threads (longer lifespan than the handle's) 98// To allow free-running threads (longer lifespan than the handle's)
99// 'Lane' are malloc/free'd and the handle only carries a pointer. 99// 'Lane' are malloc/free'd and the handle only carries a pointer.
diff --git a/src/lanesconf.h b/src/lanesconf.h
index fb4a601..8c66bd1 100644
--- a/src/lanesconf.h
+++ b/src/lanesconf.h
@@ -2,6 +2,32 @@
2 2
3#include "platform.h" 3#include "platform.h"
4 4
5// here is a place that's as good as any other to list a few coding conventions that I will endeavour to follow:
6//
7// indentation:
8// ------------
9// spaces everywhere
10// case indented inside switch braces
11// accessibility keywords indented inside class braces
12// matching braces have the same indentation
13//
14// identifiers:
15// ------------
16// style is camel case. scope of variable is optionally specified with a single lowercase letter.
17// constants: prefix k, followed by an uppercase letter
18// program-level global variable: in 'global' namespace, prefix g, followed by an uppercase letter
19// file-level static variable: in 'global' namespace, prefix s, followed by an uppercase letter
20// file-level function (static or not): no prefix, start with an uppercase letter
21// class/struct/enum type: no prefix, start with an uppercase letter
22// static class member: prefix s, followed by an uppercase letter
23// regular class member: no prefix, start with a lowercase letter
24// static class method: no prefix, start with an uppercase letter
25// regular class method: no prefix, start with a lowercase letter
26// function argument: suffix _
27// static function variable: prefix s, followed by an uppercase letter
28// function local variable: prefix l, followed by an uppercase letter
29// named lambda capture: no prefix, start with a lowercase letter
30
5#if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) 31#if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC)
6#ifdef __cplusplus 32#ifdef __cplusplus
7#define LANES_API extern "C" __declspec(dllexport) 33#define LANES_API extern "C" __declspec(dllexport)
diff --git a/src/linda.cpp b/src/linda.cpp
index 0a1ca3f..590b487 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -41,8 +41,8 @@ THE SOFTWARE.
41 41
42#include <functional> 42#include <functional>
43 43
44// xxh64 of string "CANCEL_ERROR" generated at https://www.pelock.com/products/hash-calculator 44// xxh64 of string "kLindaBatched" generated at https://www.pelock.com/products/hash-calculator
45static constexpr UniqueKey BATCH_SENTINEL{ 0x2DDFEE0968C62AA7ull, "linda.batched" }; 45static constexpr UniqueKey kLindaBatched{ 0xB8234DF772646567ull, "linda.batched" };
46 46
47// ################################################################################################# 47// #################################################################################################
48 48
@@ -64,12 +64,12 @@ static LindaFactory g_LindaFactory;
64// Any hashing will do that maps pointers to [0..Universe::nb_keepers[ consistently. 64// Any hashing will do that maps pointers to [0..Universe::nb_keepers[ consistently.
65// Pointers are often aligned by 8 or so - ignore the low order bits 65// Pointers are often aligned by 8 or so - ignore the low order bits
66// have to cast to unsigned long to avoid compilation warnings about loss of data when converting pointer-to-integer 66// have to cast to unsigned long to avoid compilation warnings about loss of data when converting pointer-to-integer
67static constexpr uintptr_t KEEPER_MAGIC_SHIFT{ 3 }; 67static constexpr uintptr_t kPointerMagicShift{ 3 };
68 68
69Linda::Linda(Universe* U_, LindaGroup group_, char const* name_, size_t len_) 69Linda::Linda(Universe* U_, LindaGroup group_, char const* name_, size_t len_)
70: DeepPrelude{ g_LindaFactory } 70: DeepPrelude{ g_LindaFactory }
71, U{ U_ } 71, U{ U_ }
72, m_keeper_index{ (group_ ? group_ : static_cast<int>(std::bit_cast<uintptr_t>(this) >> KEEPER_MAGIC_SHIFT)) % U_->keepers->nb_keepers } 72, m_keeper_index{ (group_ ? group_ : static_cast<int>(std::bit_cast<uintptr_t>(this) >> kPointerMagicShift)) % U_->keepers->nb_keepers }
73{ 73{
74 setName(name_, len_); 74 setName(name_, len_);
75} 75}
@@ -157,8 +157,8 @@ static void check_key_types(lua_State* L, int start_, int end_)
157 157
158 case LuaType::LIGHTUSERDATA: 158 case LuaType::LIGHTUSERDATA:
159 { 159 {
160 static constexpr std::array<std::reference_wrapper<UniqueKey const>, 3> to_check{ BATCH_SENTINEL, CANCEL_ERROR, NIL_SENTINEL }; 160 static constexpr std::array<std::reference_wrapper<UniqueKey const>, 3> kKeysToCheck{ kLindaBatched, kCancelError, kNilSentinel };
161 for (UniqueKey const& key : to_check) 161 for (UniqueKey const& key : kKeysToCheck)
162 { 162 {
163 if (key.equals(L, i)) 163 if (key.equals(L, i))
164 { 164 {
@@ -217,7 +217,7 @@ int Linda::ProtectedCall(lua_State* L, lua_CFunction f_)
217* 217*
218* Returns: 'true' if the value was queued 218* Returns: 'true' if the value was queued
219* 'false' for timeout (only happens when the queue size is limited) 219* 'false' for timeout (only happens when the queue size is limited)
220* nil, CANCEL_ERROR if cancelled 220* nil, kCancelError if cancelled
221*/ 221*/
222LUAG_FUNC(linda_send) 222LUAG_FUNC(linda_send)
223{ 223{
@@ -241,10 +241,10 @@ LUAG_FUNC(linda_send)
241 ++key_i; 241 ++key_i;
242 } 242 }
243 243
244 bool const as_nil_sentinel{ NIL_SENTINEL.equals(L, key_i) }; // if not nullptr, send() will silently send a single nil if nothing is provided 244 bool const as_nil_sentinel{ kNilSentinel.equals(L, key_i) }; // if not nullptr, send() will silently send a single nil if nothing is provided
245 if (as_nil_sentinel) 245 if (as_nil_sentinel)
246 { 246 {
247 // the real key to send data to is after the NIL_SENTINEL marker 247 // the real key to send data to is after the kNilSentinel marker
248 ++key_i; 248 ++key_i;
249 } 249 }
250 250
@@ -259,7 +259,7 @@ LUAG_FUNC(linda_send)
259 if (as_nil_sentinel) 259 if (as_nil_sentinel)
260 { 260 {
261 // send a single nil if nothing is provided 261 // send a single nil if nothing is provided
262 NIL_SENTINEL.pushKey(L); 262 kNilSentinel.pushKey(L);
263 } 263 }
264 else 264 else
265 { 265 {
@@ -273,7 +273,7 @@ LUAG_FUNC(linda_send)
273 CancelRequest cancel{ CancelRequest::None }; 273 CancelRequest cancel{ CancelRequest::None };
274 KeeperCallResult pushed; 274 KeeperCallResult pushed;
275 { 275 {
276 Lane* const lane{ LANE_POINTER_REGKEY.readLightUserDataValue<Lane>(L) }; 276 Lane* const lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L) };
277 Keeper* const K{ linda->whichKeeper() }; 277 Keeper* const K{ linda->whichKeeper() };
278 KeeperState const KL{ K ? K->L : nullptr }; 278 KeeperState const KL{ K ? K->L : nullptr };
279 if (KL == nullptr) 279 if (KL == nullptr)
@@ -354,7 +354,7 @@ LUAG_FUNC(linda_send)
354 { 354 {
355 case CancelRequest::Soft: 355 case CancelRequest::Soft:
356 // if user wants to soft-cancel, the call returns lanes.cancel_error 356 // if user wants to soft-cancel, the call returns lanes.cancel_error
357 CANCEL_ERROR.pushKey(L); 357 kCancelError.pushKey(L);
358 return 1; 358 return 1;
359 359
360 case CancelRequest::Hard: 360 case CancelRequest::Hard:
@@ -407,7 +407,7 @@ LUAG_FUNC(linda_receive)
407 keeper_api_t selected_keeper_receive{ nullptr }; 407 keeper_api_t selected_keeper_receive{ nullptr };
408 int expected_pushed_min{ 0 }, expected_pushed_max{ 0 }; 408 int expected_pushed_min{ 0 }, expected_pushed_max{ 0 };
409 // are we in batched mode? 409 // are we in batched mode?
410 BATCH_SENTINEL.pushKey(L); 410 kLindaBatched.pushKey(L);
411 int const is_batched{ lua501_equal(L, key_i, -1) }; 411 int const is_batched{ lua501_equal(L, key_i, -1) };
412 lua_pop(L, 1); 412 lua_pop(L, 1);
413 if (is_batched) 413 if (is_batched)
@@ -439,7 +439,7 @@ LUAG_FUNC(linda_receive)
439 expected_pushed_min = expected_pushed_max = 2; 439 expected_pushed_min = expected_pushed_max = 2;
440 } 440 }
441 441
442 Lane* const lane{ LANE_POINTER_REGKEY.readLightUserDataValue<Lane>(L) }; 442 Lane* const lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L) };
443 Keeper* const K{ linda->whichKeeper() }; 443 Keeper* const K{ linda->whichKeeper() };
444 KeeperState const KL{ K ? K->L : nullptr }; 444 KeeperState const KL{ K ? K->L : nullptr };
445 if (KL == nullptr) 445 if (KL == nullptr)
@@ -518,8 +518,8 @@ LUAG_FUNC(linda_receive)
518 switch (cancel) 518 switch (cancel)
519 { 519 {
520 case CancelRequest::Soft: 520 case CancelRequest::Soft:
521 // if user wants to soft-cancel, the call returns CANCEL_ERROR 521 // if user wants to soft-cancel, the call returns kCancelError
522 CANCEL_ERROR.pushKey(L); 522 kCancelError.pushKey(L);
523 return 1; 523 return 1;
524 524
525 case CancelRequest::Hard: 525 case CancelRequest::Hard:
@@ -582,7 +582,7 @@ LUAG_FUNC(linda_set)
582 else // linda is cancelled 582 else // linda is cancelled
583 { 583 {
584 // do nothing and return lanes.cancel_error 584 // do nothing and return lanes.cancel_error
585 CANCEL_ERROR.pushKey(L); 585 kCancelError.pushKey(L);
586 pushed.emplace(1); 586 pushed.emplace(1);
587 } 587 }
588 588
@@ -645,7 +645,7 @@ LUAG_FUNC(linda_get)
645 else // linda is cancelled 645 else // linda is cancelled
646 { 646 {
647 // do nothing and return lanes.cancel_error 647 // do nothing and return lanes.cancel_error
648 CANCEL_ERROR.pushKey(L); 648 kCancelError.pushKey(L);
649 pushed.emplace(1); 649 pushed.emplace(1);
650 } 650 }
651 // an error can be raised if we attempt to read an unregistered function 651 // an error can be raised if we attempt to read an unregistered function
@@ -689,7 +689,7 @@ LUAG_FUNC(linda_limit)
689 else // linda is cancelled 689 else // linda is cancelled
690 { 690 {
691 // do nothing and return lanes.cancel_error 691 // do nothing and return lanes.cancel_error
692 CANCEL_ERROR.pushKey(L); 692 kCancelError.pushKey(L);
693 pushed.emplace(1); 693 pushed.emplace(1);
694 } 694 }
695 // propagate pushed boolean if any 695 // propagate pushed boolean if any
@@ -956,10 +956,10 @@ void LindaFactory::createMetatable(lua_State* L) const
956 luaL_setfuncs(L, s_LindaMT, 0); 956 luaL_setfuncs(L, s_LindaMT, 0);
957 957
958 // some constants 958 // some constants
959 BATCH_SENTINEL.pushKey(L); 959 kLindaBatched.pushKey(L);
960 lua_setfield(L, -2, "batched"); 960 lua_setfield(L, -2, "batched");
961 961
962 NIL_SENTINEL.pushKey(L); 962 kNilSentinel.pushKey(L);
963 lua_setfield(L, -2, "null"); 963 lua_setfield(L, -2, "null");
964 964
965 STACK_CHECK(L, 1); 965 STACK_CHECK(L, 1);
diff --git a/src/linda.h b/src/linda.h
index 559ef24..f3b1844 100644
--- a/src/linda.h
+++ b/src/linda.h
@@ -50,6 +50,7 @@ class Linda : public DeepPrelude // Deep userdata MUST start with this header
50 ~Linda(); 50 ~Linda();
51 Linda(Universe* U_, LindaGroup group_, char const* name_, size_t len_); 51 Linda(Universe* U_, LindaGroup group_, char const* name_, size_t len_);
52 Linda() = delete; 52 Linda() = delete;
53 // non-copyable, non-movable
53 Linda(Linda const&) = delete; 54 Linda(Linda const&) = delete;
54 Linda(Linda const&&) = delete; 55 Linda(Linda const&&) = delete;
55 Linda& operator=(Linda const&) = delete; 56 Linda& operator=(Linda const&) = delete;
diff --git a/src/state.cpp b/src/state.cpp
index 2a69a46..379b63e 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -200,15 +200,15 @@ static void copy_one_time_settings(Universe* U, SourceState L1, DestState L2)
200 200
201 DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "copy_one_time_settings()\n" INDENT_END)); 201 DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "copy_one_time_settings()\n" INDENT_END));
202 202
203 CONFIG_REGKEY.pushValue(L1); // config 203 kConfigRegKey.pushValue(L1); // config
204 // copy settings from from source to destination registry 204 // copy settings from from source to destination registry
205 InterCopyContext c{ U, L2, L1, {}, {}, {}, {}, {} }; 205 InterCopyContext c{ U, L2, L1, {}, {}, {}, {}, {} };
206 if (c.inter_move(1) != InterCopyResult::Success) // // config 206 if (c.inter_move(1) != InterCopyResult::Success) // // config
207 { 207 {
208 luaL_error(L1, "failed to copy settings when loading lanes.core"); // doesn't return 208 luaL_error(L1, "failed to copy settings when loading lanes.core"); // doesn't return
209 } 209 }
210 // set L2:_R[CONFIG_REGKEY] = settings 210 // set L2:_R[kConfigRegKey] = settings
211 CONFIG_REGKEY.setValue(L2, [](lua_State* L) { lua_insert(L, -2); }); // config 211 kConfigRegKey.setValue(L2, [](lua_State* L) { lua_insert(L, -2); }); // config
212 STACK_CHECK(L2, 0); 212 STACK_CHECK(L2, 0);
213 STACK_CHECK(L1, 0); 213 STACK_CHECK(L1, 0);
214} 214}
@@ -301,7 +301,7 @@ void call_on_state_create(Universe* U, lua_State* L, lua_State* from_, LookupMod
301 STACK_CHECK(L, 0); 301 STACK_CHECK(L, 0);
302 return; 302 return;
303 } 303 }
304 CONFIG_REGKEY.pushValue(L); // {} 304 kConfigRegKey.pushValue(L); // {}
305 STACK_CHECK(L, 1); 305 STACK_CHECK(L, 1);
306 lua_getfield(L, -1, "on_state_create"); // {} on_state_create() 306 lua_getfield(L, -1, "on_state_create"); // {} on_state_create()
307 lua_remove(L, -2); // on_state_create() 307 lua_remove(L, -2); // on_state_create()
@@ -344,7 +344,7 @@ lua_State* luaG_newstate(Universe* U, SourceState from_, char const* libs_)
344 STACK_CHECK(L, 0); 344 STACK_CHECK(L, 0);
345 345
346 // we'll need this every time we transfer some C function from/to this state 346 // we'll need this every time we transfer some C function from/to this state
347 LOOKUP_REGKEY.setValue(L, [](lua_State* L) { lua_newtable(L); }); 347 kLookupRegKey.setValue(L, [](lua_State* L) { lua_newtable(L); });
348 STACK_CHECK(L, 0); 348 STACK_CHECK(L, 0);
349 349
350 // neither libs (not even 'base') nor special init func: we are done 350 // neither libs (not even 'base') nor special init func: we are done
@@ -427,7 +427,7 @@ lua_State* luaG_newstate(Universe* U, SourceState from_, char const* libs_)
427 427
428#if 1 && USE_DEBUG_SPEW() 428#if 1 && USE_DEBUG_SPEW()
429 // dump the lookup database contents 429 // dump the lookup database contents
430 LOOKUP_REGKEY.pushValue(L); // {} 430 kLookupRegKey.pushValue(L); // {}
431 lua_pushnil(L); // {} nil 431 lua_pushnil(L); // {} nil
432 while (lua_next(L, -2)) // {} k v 432 while (lua_next(L, -2)) // {} k v
433 { 433 {
diff --git a/src/threading.cpp b/src/threading.cpp
index c7928c1..acc79d8 100644
--- a/src/threading.cpp
+++ b/src/threading.cpp
@@ -350,7 +350,7 @@ static int const gs_prio_remap[] =
350 350
351[[nodiscard]] static 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 == kThreadPrioDefault)
354 prio = 0; 354 prio = 0;
355 // prio range [-3,+3] was checked by the caller 355 // prio range [-3,+3] was checked by the caller
356 return gs_prio_remap[prio + 3]; 356 return gs_prio_remap[prio + 3];
diff --git a/src/threading.h b/src/threading.h
index e13932b..7d24ef0 100644
--- a/src/threading.h
+++ b/src/threading.h
@@ -15,7 +15,7 @@
15#define THREADAPI THREADAPI_PTHREAD 15#define THREADAPI THREADAPI_PTHREAD
16#endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) 16#endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC)
17 17
18static constexpr int THREAD_PRIO_DEFAULT{ -999 }; 18static constexpr int kThreadPrioDefault{ -999 };
19 19
20// ################################################################################################# 20// #################################################################################################
21// ################################################################################################# 21// #################################################################################################
@@ -40,8 +40,8 @@ static constexpr int THREAD_PRIO_DEFAULT{ -999 };
40#pragma message( "The value of _WIN32_WINNT: " XSTR(_WIN32_WINNT)) 40#pragma message( "The value of _WIN32_WINNT: " XSTR(_WIN32_WINNT))
41*/ 41*/
42 42
43static constexpr int THREAD_PRIO_MIN{ -3 }; 43static constexpr int kThreadPrioMin{ -3 };
44static constexpr int THREAD_PRIO_MAX{ +3 }; 44static constexpr int kThreadPrioMax{ +3 };
45 45
46// ################################################################################################# 46// #################################################################################################
47// ################################################################################################# 47// #################################################################################################
@@ -58,11 +58,11 @@ static constexpr int THREAD_PRIO_MAX{ +3 };
58#include <pthread.h> 58#include <pthread.h>
59 59
60#if defined(PLATFORM_LINUX) && !defined(LINUX_SCHED_RR) 60#if defined(PLATFORM_LINUX) && !defined(LINUX_SCHED_RR)
61static constexpr int THREAD_PRIO_MIN{ 0 }; 61static constexpr int kThreadPrioMin{ 0 };
62#else 62#else
63static constexpr int THREAD_PRIO_MIN{ -3 }; 63static constexpr int kThreadPrioMin{ -3 };
64#endif 64#endif
65static constexpr int THREAD_PRIO_MAX{ +3 }; 65static constexpr int kThreadPrioMax{ +3 };
66 66
67#endif // THREADAPI == THREADAPI_PTHREAD 67#endif // THREADAPI == THREADAPI_PTHREAD
68// ################################################################################################# 68// #################################################################################################
diff --git a/src/tools.cpp b/src/tools.cpp
index a25fb2b..aa8f927 100644
--- a/src/tools.cpp
+++ b/src/tools.cpp
@@ -37,8 +37,8 @@ THE SOFTWARE.
37 37
38DEBUGSPEW_CODE(char const* const DebugSpewIndentScope::debugspew_indent = "----+----!----+----!----+----!----+----!----+----!----+----!----+----!----+"); 38DEBUGSPEW_CODE(char const* const DebugSpewIndentScope::debugspew_indent = "----+----!----+----!----+----!----+----!----+----!----+----!----+----!----+");
39 39
40// crc64/we of string "LOOKUPCACHE_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 40// xxh64 of string "kLookupCacheRegKey" generated at https://www.pelock.com/products/hash-calculator
41static constexpr RegistryUniqueKey LOOKUPCACHE_REGKEY{ 0x837A68DFC6FCB716ull }; 41static constexpr RegistryUniqueKey kLookupCacheRegKey{ 0x9BF75F84E54B691Bull };
42 42
43// ################################################################################################# 43// #################################################################################################
44 44
@@ -480,7 +480,7 @@ void populate_func_lookup_table(lua_State* L, int i_, char const* name_)
480 DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); 480 DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U });
481 STACK_GROW(L, 3); 481 STACK_GROW(L, 3);
482 STACK_CHECK_START_REL(L, 0); 482 STACK_CHECK_START_REL(L, 0);
483 LOOKUP_REGKEY.pushValue(L); // {} 483 kLookupRegKey.pushValue(L); // {}
484 STACK_CHECK(L, 1); 484 STACK_CHECK(L, 1);
485 LUA_ASSERT(L, lua_istable(L, -1)); 485 LUA_ASSERT(L, lua_istable(L, -1));
486 if (lua_type(L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function 486 if (lua_type(L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function
@@ -510,12 +510,12 @@ void populate_func_lookup_table(lua_State* L, int i_, char const* name_)
510 STACK_CHECK(L, 2); 510 STACK_CHECK(L, 2);
511 } 511 }
512 // retrieve the cache, create it if we haven't done it yet 512 // retrieve the cache, create it if we haven't done it yet
513 LOOKUPCACHE_REGKEY.pushValue(L); // {} {fqn} {cache}? 513 kLookupCacheRegKey.pushValue(L); // {} {fqn} {cache}?
514 if (lua_isnil(L, -1)) 514 if (lua_isnil(L, -1))
515 { 515 {
516 lua_pop(L, 1); // {} {fqn} 516 lua_pop(L, 1); // {} {fqn}
517 lua_newtable(L); // {} {fqn} {cache} 517 lua_newtable(L); // {} {fqn} {cache}
518 LOOKUPCACHE_REGKEY.setValue(L, [](lua_State* L) { lua_pushvalue(L, -2); }); 518 kLookupCacheRegKey.setValue(L, [](lua_State* L) { lua_pushvalue(L, -2); });
519 STACK_CHECK(L, 3); 519 STACK_CHECK(L, 3);
520 } 520 }
521 // process everything we find in that table, filling in lookup data for all functions and tables we see there 521 // process everything we find in that table, filling in lookup data for all functions and tables we see there
@@ -534,8 +534,8 @@ void populate_func_lookup_table(lua_State* L, int i_, char const* name_)
534 534
535/*---=== Inter-state copying ===---*/ 535/*---=== Inter-state copying ===---*/
536 536
537// crc64/we of string "REG_MTID" generated at http://www.nitrxgen.net/hashgen/ 537// xxh64 of string "kMtIdRegKey" generated at https://www.pelock.com/products/hash-calculator
538static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull }; 538static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull };
539 539
540/* 540/*
541* Get a unique ID for metatable at [i]. 541* Get a unique ID for metatable at [i].
@@ -547,12 +547,12 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull };
547 STACK_GROW(L, 3); 547 STACK_GROW(L, 3);
548 548
549 STACK_CHECK_START_REL(L, 0); 549 STACK_CHECK_START_REL(L, 0);
550 push_registry_subtable(L, REG_MTID); // ... _R[REG_MTID] 550 push_registry_subtable(L, kMtIdRegKey); // ... _R[kMtIdRegKey]
551 lua_pushvalue(L, i); // ... _R[REG_MTID] {mt} 551 lua_pushvalue(L, i); // ... _R[kMtIdRegKey] {mt}
552 lua_rawget(L, -2); // ... _R[REG_MTID] mtk? 552 lua_rawget(L, -2); // ... _R[kMtIdRegKey] mtk?
553 553
554 lua_Integer id{ lua_tointeger(L, -1) }; // 0 for nil 554 lua_Integer id{ lua_tointeger(L, -1) }; // 0 for nil
555 lua_pop(L, 1); // ... _R[REG_MTID] 555 lua_pop(L, 1); // ... _R[kMtIdRegKey]
556 STACK_CHECK(L, 1); 556 STACK_CHECK(L, 1);
557 557
558 if (id == 0) 558 if (id == 0)
@@ -560,13 +560,13 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull };
560 id = U->next_mt_id.fetch_add(1, std::memory_order_relaxed); 560 id = U->next_mt_id.fetch_add(1, std::memory_order_relaxed);
561 561
562 // Create two-way references: id_uint <-> table 562 // Create two-way references: id_uint <-> table
563 lua_pushvalue(L, i); // ... _R[REG_MTID] {mt} 563 lua_pushvalue(L, i); // ... _R[kMtIdRegKey] {mt}
564 lua_pushinteger(L, id); // ... _R[REG_MTID] {mt} id 564 lua_pushinteger(L, id); // ... _R[kMtIdRegKey] {mt} id
565 lua_rawset(L, -3); // ... _R[REG_MTID] 565 lua_rawset(L, -3); // ... _R[kMtIdRegKey]
566 566
567 lua_pushinteger(L, id); // ... _R[REG_MTID] id 567 lua_pushinteger(L, id); // ... _R[kMtIdRegKey] id
568 lua_pushvalue(L, i); // ... _R[REG_MTID] id {mt} 568 lua_pushvalue(L, i); // ... _R[kMtIdRegKey] id {mt}
569 lua_rawset(L, -3); // ... _R[REG_MTID] 569 lua_rawset(L, -3); // ... _R[kMtIdRegKey]
570 } 570 }
571 lua_pop(L, 1); // ... 571 lua_pop(L, 1); // ...
572 STACK_CHECK(L, 0); 572 STACK_CHECK(L, 0);
@@ -628,7 +628,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull };
628 else 628 else
629 { 629 {
630 // fetch the name from the source state's lookup table 630 // fetch the name from the source state's lookup table
631 LOOKUP_REGKEY.pushValue(L); // ... v ... {} 631 kLookupRegKey.pushValue(L); // ... v ... {}
632 STACK_CHECK( L, 1); 632 STACK_CHECK( L, 1);
633 LUA_ASSERT(L, lua_istable( L, -1)); 633 LUA_ASSERT(L, lua_istable( L, -1));
634 lua_pushvalue( L, i); // ... v ... {} v 634 lua_pushvalue( L, i); // ... v ... {} v
@@ -700,7 +700,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull };
700 700
701 case LookupMode::LaneBody: 701 case LookupMode::LaneBody:
702 case LookupMode::FromKeeper: 702 case LookupMode::FromKeeper:
703 LOOKUP_REGKEY.pushValue(L2); // {} 703 kLookupRegKey.pushValue(L2); // {}
704 STACK_CHECK(L2, 1); 704 STACK_CHECK(L2, 1);
705 LUA_ASSERT(L1, lua_istable(L2, -1)); 705 LUA_ASSERT(L1, lua_istable(L2, -1));
706 lua_pushlstring(L2, fqn, len); // {} "f.q.n" 706 lua_pushlstring(L2, fqn, len); // {} "f.q.n"
@@ -1005,7 +1005,7 @@ void InterCopyContext::lookup_native_func() const
1005 1005
1006 case LookupMode::LaneBody: 1006 case LookupMode::LaneBody:
1007 case LookupMode::FromKeeper: 1007 case LookupMode::FromKeeper:
1008 LOOKUP_REGKEY.pushValue(L2); // {} 1008 kLookupRegKey.pushValue(L2); // {}
1009 STACK_CHECK(L2, 1); 1009 STACK_CHECK(L2, 1);
1010 LUA_ASSERT(L1, lua_istable(L2, -1)); 1010 LUA_ASSERT(L1, lua_istable(L2, -1));
1011 lua_pushlstring(L2, fqn, len); // {} "f.q.n" 1011 lua_pushlstring(L2, fqn, len); // {} "f.q.n"
@@ -1324,30 +1324,30 @@ void InterCopyContext::copy_cached_func() const
1324 STACK_CHECK_START_REL(L2, 0); 1324 STACK_CHECK_START_REL(L2, 0);
1325 STACK_GROW(L2, 4); 1325 STACK_GROW(L2, 4);
1326 // do we already know this metatable? 1326 // do we already know this metatable?
1327 push_registry_subtable(L2, REG_MTID); // _R[REG_MTID] 1327 push_registry_subtable(L2, kMtIdRegKey); // _R[kMtIdRegKey]
1328 lua_pushinteger(L2, mt_id); // _R[REG_MTID] id 1328 lua_pushinteger(L2, mt_id); // _R[kMtIdRegKey] id
1329 lua_rawget(L2, -2); // _R[REG_MTID] mt|nil 1329 lua_rawget(L2, -2); // _R[kMtIdRegKey] mt|nil
1330 STACK_CHECK(L2, 2); 1330 STACK_CHECK(L2, 2);
1331 1331
1332 if (lua_isnil(L2, -1)) 1332 if (lua_isnil(L2, -1))
1333 { // L2 did not know the metatable 1333 { // L2 did not know the metatable
1334 lua_pop(L2, 1); // _R[REG_MTID] 1334 lua_pop(L2, 1); // _R[kMtIdRegKey]
1335 InterCopyContext const c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; 1335 InterCopyContext const c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name };
1336 if (!c.inter_copy_one()) // _R[REG_MTID] mt? 1336 if (!c.inter_copy_one()) // _R[kMtIdRegKey] mt?
1337 { 1337 {
1338 luaL_error(L1, "Error copying a metatable"); // doesn't return 1338 luaL_error(L1, "Error copying a metatable"); // doesn't return
1339 } 1339 }
1340 1340
1341 STACK_CHECK(L2, 2); // _R[REG_MTID] mt 1341 STACK_CHECK(L2, 2); // _R[kMtIdRegKey] mt
1342 // mt_id -> metatable 1342 // mt_id -> metatable
1343 lua_pushinteger(L2, mt_id); // _R[REG_MTID] mt id 1343 lua_pushinteger(L2, mt_id); // _R[kMtIdRegKey] mt id
1344 lua_pushvalue(L2, -2); // _R[REG_MTID] mt id mt 1344 lua_pushvalue(L2, -2); // _R[kMtIdRegKey] mt id mt
1345 lua_rawset(L2, -4); // _R[REG_MTID] mt 1345 lua_rawset(L2, -4); // _R[kMtIdRegKey] mt
1346 1346
1347 // metatable -> mt_id 1347 // metatable -> mt_id
1348 lua_pushvalue(L2, -1); // _R[REG_MTID] mt mt 1348 lua_pushvalue(L2, -1); // _R[kMtIdRegKey] mt mt
1349 lua_pushinteger(L2, mt_id); // _R[REG_MTID] mt mt id 1349 lua_pushinteger(L2, mt_id); // _R[kMtIdRegKey] mt mt id
1350 lua_rawset(L2, -4); // _R[REG_MTID] mt 1350 lua_rawset(L2, -4); // _R[kMtIdRegKey] mt
1351 STACK_CHECK(L2, 2); 1351 STACK_CHECK(L2, 2);
1352 } 1352 }
1353 lua_remove(L2, -2); // mt 1353 lua_remove(L2, -2); // mt
@@ -1432,12 +1432,6 @@ void InterCopyContext::inter_copy_keyvaluepair() const
1432 1432
1433// ################################################################################################# 1433// #################################################################################################
1434 1434
1435/*
1436* The clone cache is a weak valued table listing all clones, indexed by their userdatapointer
1437* fnv164 of string "CLONABLES_CACHE_KEY" generated at https://www.pelock.com/products/hash-calculator
1438*/
1439static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull };
1440
1441[[nodiscard]] bool InterCopyContext::copyclone() const 1435[[nodiscard]] bool InterCopyContext::copyclone() const
1442{ 1436{
1443 SourceIndex const L1_i{ lua_absindex(L1, this->L1_i) }; 1437 SourceIndex const L1_i{ lua_absindex(L1, this->L1_i) };
@@ -1848,7 +1842,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull };
1848*/ 1842*/
1849[[nodiscard]] bool InterCopyContext::inter_copy_one() const 1843[[nodiscard]] bool InterCopyContext::inter_copy_one() const
1850{ 1844{
1851 static constexpr int pod_mask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); 1845 static constexpr int kPODmask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING);
1852 STACK_GROW(L2, 1); 1846 STACK_GROW(L2, 1);
1853 STACK_CHECK_START_REL(L1, 0); // L1 // L2 1847 STACK_CHECK_START_REL(L1, 0); // L1 // L2
1854 STACK_CHECK_START_REL(L2, 0); // L1 // L2 1848 STACK_CHECK_START_REL(L2, 0); // L1 // L2
@@ -1860,7 +1854,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull };
1860 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s %s: " INDENT_END, lua_type_names[static_cast<int>(val_type)], vt_names[static_cast<int>(vt)])); 1854 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s %s: " INDENT_END, lua_type_names[static_cast<int>(val_type)], vt_names[static_cast<int>(vt)]));
1861 1855
1862 // Non-POD can be skipped if its metatable contains { __lanesignore = true } 1856 // Non-POD can be skipped if its metatable contains { __lanesignore = true }
1863 if (((1 << static_cast<int>(val_type)) & pod_mask) == 0) 1857 if (((1 << static_cast<int>(val_type)) & kPODmask) == 0)
1864 { 1858 {
1865 if (lua_getmetatable(L1, L1_i)) // ... mt 1859 if (lua_getmetatable(L1, L1_i)) // ... mt
1866 { 1860 {
diff --git a/src/tools.h b/src/tools.h
index 755a0c6..53edbe2 100644
--- a/src/tools.h
+++ b/src/tools.h
@@ -87,8 +87,8 @@ void initialize_allocator_function(Universe* U, lua_State* L);
87 87
88// ################################################################################################# 88// #################################################################################################
89 89
90// crc64/we of string "CONFIG_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 90// xxh64 of string "kConfigRegKey" generated at https://www.pelock.com/products/hash-calculator
91static constexpr RegistryUniqueKey CONFIG_REGKEY{ 0x31CD24894EAE8624ull }; // registry key to access the configuration 91static constexpr RegistryUniqueKey kConfigRegKey{ 0x608379D20A398046ull }; // registry key to access the configuration
92 92
93// crc64/we of string "LOOKUP_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 93// xxh64 of string "kLookupRegKey" generated at https://www.pelock.com/products/hash-calculator
94static constexpr RegistryUniqueKey LOOKUP_REGKEY{ 0x5051ED67EE7B51A1ull }; // registry key to access the lookup database 94static constexpr RegistryUniqueKey kLookupRegKey{ 0xBF1FC5CF3C6DD47Bull }; // registry key to access the lookup database
diff --git a/src/universe.cpp b/src/universe.cpp
index fb10067..4eca0c9 100644
--- a/src/universe.cpp
+++ b/src/universe.cpp
@@ -36,10 +36,10 @@ THE SOFTWARE.
36#include "macros_and_utils.h" 36#include "macros_and_utils.h"
37#include "uniquekey.h" 37#include "uniquekey.h"
38 38
39// xxh64 of string "UNIVERSE_FULL_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 39// xxh64 of string "kUniverseFullRegKey" generated at https://www.pelock.com/products/hash-calculator
40static constexpr RegistryUniqueKey UNIVERSE_FULL_REGKEY{ 0x99CA130C09EDC074ull }; 40static constexpr RegistryUniqueKey kUniverseFullRegKey{ 0x1C2D76870DD9DD9Full };
41// xxh64 of string "UNIVERSE_LIGHT_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 41// xxh64 of string "kUniverseLightRegKey" generated at https://www.pelock.com/products/hash-calculator
42static constexpr RegistryUniqueKey UNIVERSE_LIGHT_REGKEY{ 0x3663C07C742CEB81ull }; 42static constexpr RegistryUniqueKey kUniverseLightRegKey{ 0x48BBE9CEAB0BA04Full };
43 43
44// ################################################################################################# 44// #################################################################################################
45 45
@@ -79,8 +79,8 @@ Universe* universe_create(lua_State* L)
79 Universe* const U{ lua_newuserdatauv<Universe>(L, 0) }; // universe 79 Universe* const U{ lua_newuserdatauv<Universe>(L, 0) }; // universe
80 U->Universe::Universe(); 80 U->Universe::Universe();
81 STACK_CHECK_START_REL(L, 1); 81 STACK_CHECK_START_REL(L, 1);
82 UNIVERSE_FULL_REGKEY.setValue(L, [](lua_State* L) { lua_pushvalue(L, -2); }); 82 kUniverseFullRegKey.setValue(L, [](lua_State* L) { lua_pushvalue(L, -2); });
83 UNIVERSE_LIGHT_REGKEY.setValue(L, [U](lua_State* L) { lua_pushlightuserdata(L, U); }); 83 kUniverseLightRegKey.setValue(L, [U](lua_State* L) { lua_pushlightuserdata(L, U); });
84 STACK_CHECK(L, 1); 84 STACK_CHECK(L, 1);
85 return U; 85 return U;
86} 86}
@@ -91,7 +91,7 @@ void universe_store(lua_State* L, Universe* U)
91{ 91{
92 LUA_ASSERT(L, !U || universe_get(L) == nullptr); 92 LUA_ASSERT(L, !U || universe_get(L) == nullptr);
93 STACK_CHECK_START_REL(L, 0); 93 STACK_CHECK_START_REL(L, 0);
94 UNIVERSE_LIGHT_REGKEY.setValue(L, [U](lua_State* L) { U ? lua_pushlightuserdata(L, U) : lua_pushnil(L); }); 94 kUniverseLightRegKey.setValue(L, [U](lua_State* L) { U ? lua_pushlightuserdata(L, U) : lua_pushnil(L); });
95 STACK_CHECK(L, 0); 95 STACK_CHECK(L, 0);
96} 96}
97 97
@@ -100,7 +100,7 @@ void universe_store(lua_State* L, Universe* U)
100Universe* universe_get(lua_State* L) 100Universe* universe_get(lua_State* L)
101{ 101{
102 STACK_CHECK_START_REL(L, 0); 102 STACK_CHECK_START_REL(L, 0);
103 Universe* const universe{ UNIVERSE_LIGHT_REGKEY.readLightUserDataValue<Universe>(L) }; 103 Universe* const universe{ kUniverseLightRegKey.readLightUserDataValue<Universe>(L) };
104 STACK_CHECK(L, 0); 104 STACK_CHECK(L, 0);
105 return universe; 105 return universe;
106} 106}
diff --git a/src/universe.h b/src/universe.h
index d0d7864..bdc871d 100644
--- a/src/universe.h
+++ b/src/universe.h
@@ -178,6 +178,7 @@ class Universe
178 178
179 Universe(); 179 Universe();
180 ~Universe() = default; 180 ~Universe() = default;
181 // non-copyable, non-movable
181 Universe(Universe const&) = delete; 182 Universe(Universe const&) = delete;
182 Universe(Universe&&) = delete; 183 Universe(Universe&&) = delete;
183 Universe& operator=(Universe const&) = delete; 184 Universe& operator=(Universe const&) = delete;