diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2025-02-05 12:27:02 +0100 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2025-02-05 12:27:02 +0100 |
| commit | 05e4cce366cccf92ad88f80695efa548fae187de (patch) | |
| tree | 3332753154ecd89a87d7fdd6a4f9383d1b66ed1f /src | |
| parent | 59ae58fd31d63c261372bd5a36765328583bc1b6 (diff) | |
| download | lanes-05e4cce366cccf92ad88f80695efa548fae187de.tar.gz lanes-05e4cce366cccf92ad88f80695efa548fae187de.tar.bz2 lanes-05e4cce366cccf92ad88f80695efa548fae187de.zip | |
Minor internal code tweaks
* mark all eligible classes Final
* new TableIndex strong type
* buildfixes for HAVE_DEBUGSPEW()
* overridden virtual destructors tagged as such
Diffstat (limited to 'src')
| -rw-r--r-- | src/debug.hpp | 2 | ||||
| -rw-r--r-- | src/debugspew.hpp | 2 | ||||
| -rw-r--r-- | src/intercopycontext.cpp | 2 | ||||
| -rw-r--r-- | src/intercopycontext.hpp | 2 | ||||
| -rw-r--r-- | src/keeper.cpp | 2 | ||||
| -rw-r--r-- | src/lane.cpp | 4 | ||||
| -rw-r--r-- | src/lane.hpp | 2 | ||||
| -rw-r--r-- | src/lanes.cpp | 2 | ||||
| -rw-r--r-- | src/linda.hpp | 4 | ||||
| -rw-r--r-- | src/lindafactory.hpp | 3 | ||||
| -rw-r--r-- | src/macros_and_utils.hpp | 2 | ||||
| -rw-r--r-- | src/nameof.cpp | 6 | ||||
| -rw-r--r-- | src/stackindex.hpp | 5 | ||||
| -rw-r--r-- | src/state.cpp | 2 | ||||
| -rw-r--r-- | src/tools.cpp | 24 | ||||
| -rw-r--r-- | src/tools.hpp | 5 | ||||
| -rw-r--r-- | src/unique.hpp | 2 | ||||
| -rw-r--r-- | src/uniquekey.hpp | 2 | ||||
| -rw-r--r-- | src/universe.hpp | 4 |
19 files changed, 40 insertions, 37 deletions
diff --git a/src/debug.hpp b/src/debug.hpp index 39d106a..66541c0 100644 --- a/src/debug.hpp +++ b/src/debug.hpp | |||
| @@ -30,7 +30,7 @@ inline void LUA_ASSERT_IMPL(lua_State* const L_, bool const cond_, std::string_v | |||
| 30 | #define LUA_ASSERT(L_, cond_) LUA_ASSERT_IMPL(L_, (cond_) ? true : false, #cond_) | 30 | #define LUA_ASSERT(L_, cond_) LUA_ASSERT_IMPL(L_, (cond_) ? true : false, #cond_) |
| 31 | #define LUA_ASSERT_CODE(code_) code_ | 31 | #define LUA_ASSERT_CODE(code_) code_ |
| 32 | 32 | ||
| 33 | class StackChecker | 33 | class StackChecker final |
| 34 | { | 34 | { |
| 35 | private: | 35 | private: |
| 36 | lua_State* const L; | 36 | lua_State* const L; |
diff --git a/src/debugspew.hpp b/src/debugspew.hpp index 1eb5556..88bdbcc 100644 --- a/src/debugspew.hpp +++ b/src/debugspew.hpp | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | #if USE_DEBUG_SPEW() | 8 | #if USE_DEBUG_SPEW() |
| 9 | 9 | ||
| 10 | class DebugSpewIndentScope | 10 | class DebugSpewIndentScope final |
| 11 | { | 11 | { |
| 12 | private: | 12 | private: |
| 13 | Universe* const U{}; | 13 | Universe* const U{}; |
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index fd6b5a5..6b3d282 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
| @@ -1279,7 +1279,7 @@ InterCopyResult InterCopyContext::interCopyPackage() const | |||
| 1279 | { | 1279 | { |
| 1280 | DEBUGSPEW_CODE(DebugSpew(U) << "InterCopyContext::interCopyPackage()" << std::endl); | 1280 | DEBUGSPEW_CODE(DebugSpew(U) << "InterCopyContext::interCopyPackage()" << std::endl); |
| 1281 | 1281 | ||
| 1282 | class OnExit | 1282 | class OnExit final |
| 1283 | { | 1283 | { |
| 1284 | private: | 1284 | private: |
| 1285 | lua_State* const L2; | 1285 | lua_State* const L2; |
diff --git a/src/intercopycontext.hpp b/src/intercopycontext.hpp index 7008919..cc84017 100644 --- a/src/intercopycontext.hpp +++ b/src/intercopycontext.hpp | |||
| @@ -25,7 +25,7 @@ enum class InterCopyResult | |||
| 25 | 25 | ||
| 26 | DECLARE_UNIQUE_TYPE(CacheIndex, StackIndex); | 26 | DECLARE_UNIQUE_TYPE(CacheIndex, StackIndex); |
| 27 | DECLARE_UNIQUE_TYPE(SourceIndex, StackIndex); | 27 | DECLARE_UNIQUE_TYPE(SourceIndex, StackIndex); |
| 28 | class InterCopyContext | 28 | class InterCopyContext final |
| 29 | { | 29 | { |
| 30 | public: | 30 | public: |
| 31 | Universe* const U; | 31 | Universe* const U; |
diff --git a/src/keeper.cpp b/src/keeper.cpp index 2d9d800..43f3125 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
| @@ -60,7 +60,7 @@ namespace { | |||
| 60 | // ################################################################################################# | 60 | // ################################################################################################# |
| 61 | 61 | ||
| 62 | // the full userdata associated to a given Linda key to store its contents | 62 | // the full userdata associated to a given Linda key to store its contents |
| 63 | class KeyUD | 63 | class KeyUD final |
| 64 | { | 64 | { |
| 65 | private: | 65 | private: |
| 66 | static constexpr UserValueIndex kContentsTableIndex{ 1 }; | 66 | static constexpr UserValueIndex kContentsTableIndex{ 1 }; |
diff --git a/src/lane.cpp b/src/lane.cpp index 7664dd6..c3f2996 100644 --- a/src/lane.cpp +++ b/src/lane.cpp | |||
| @@ -188,7 +188,7 @@ static LUAG_FUNC(lane_join) | |||
| 188 | break; | 188 | break; |
| 189 | 189 | ||
| 190 | default: | 190 | default: |
| 191 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "Unknown Lane status: " << static_cast<int>(_lane->status) << std::endl); | 191 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "Unknown Lane status: " << static_cast<int>(_lane->status.load(std::memory_order_relaxed)) << std::endl); |
| 192 | LUA_ASSERT(L_, false); | 192 | LUA_ASSERT(L_, false); |
| 193 | _ret = 0; | 193 | _ret = 0; |
| 194 | } | 194 | } |
| @@ -766,7 +766,7 @@ static void lane_main(Lane* const lane_) | |||
| 766 | // in case of error and if it exists, fetch stack trace from registry and push it | 766 | // in case of error and if it exists, fetch stack trace from registry and push it |
| 767 | lane_->nresults += PushStackTrace(_L, lane_->errorTraceLevel, _rc, StackIndex{ 1 }); // L: retvals|error [trace] | 767 | lane_->nresults += PushStackTrace(_L, lane_->errorTraceLevel, _rc, StackIndex{ 1 }); // L: retvals|error [trace] |
| 768 | 768 | ||
| 769 | DEBUGSPEW_CODE(DebugSpew(lane_->U) << "Lane " << _L << " body: " << GetErrcodeName(_rc) << " (" << (kCancelError.equals(_L, 1) ? "cancelled" : luaG_typename(_L, 1)) << ")" << std::endl); | 769 | DEBUGSPEW_CODE(DebugSpew(lane_->U) << "Lane " << _L << " body: " << GetErrcodeName(_rc) << " (" << (kCancelError.equals(_L, StackIndex{ 1 }) ? "cancelled" : luaG_typename(_L, StackIndex{ 1 })) << ")" << std::endl); |
| 770 | // Call finalizers, if the script has set them up. | 770 | // Call finalizers, if the script has set them up. |
| 771 | // If the lane is not a coroutine, there is only a regular state, so everything is the same whether we use S or L. | 771 | // If the lane is not a coroutine, there is only a regular state, so everything is the same whether we use S or L. |
| 772 | // If the lane is a coroutine, this has to be done from the master state (S), not the thread (L), because we can't lua_pcall in a thread state | 772 | // If the lane is a coroutine, this has to be done from the master state (S), not the thread (L), because we can't lua_pcall in a thread state |
diff --git a/src/lane.hpp b/src/lane.hpp index 595bf4d..4b0acab 100644 --- a/src/lane.hpp +++ b/src/lane.hpp | |||
| @@ -50,7 +50,7 @@ enum class WakeLane | |||
| 50 | Yes | 50 | Yes |
| 51 | }; | 51 | }; |
| 52 | 52 | ||
| 53 | class Lane | 53 | class Lane final |
| 54 | { | 54 | { |
| 55 | public: | 55 | public: |
| 56 | /* | 56 | /* |
diff --git a/src/lanes.cpp b/src/lanes.cpp index 87f9a90..678540d 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
| @@ -286,7 +286,7 @@ LUAG_FUNC(lane_new) | |||
| 286 | raise_luaL_error(L_, "could not create lane: out of memory"); | 286 | raise_luaL_error(L_, "could not create lane: out of memory"); |
| 287 | } | 287 | } |
| 288 | 288 | ||
| 289 | class OnExit | 289 | class OnExit final |
| 290 | { | 290 | { |
| 291 | private: | 291 | private: |
| 292 | lua_State* const L; | 292 | lua_State* const L; |
diff --git a/src/linda.hpp b/src/linda.hpp index 65bca9f..33fc504 100644 --- a/src/linda.hpp +++ b/src/linda.hpp | |||
| @@ -15,11 +15,11 @@ static constexpr UniqueKey kLindaBatched{ 0xB8234DF772646567ull, "linda.batched" | |||
| 15 | 15 | ||
| 16 | DECLARE_UNIQUE_TYPE(LindaGroup, int); | 16 | DECLARE_UNIQUE_TYPE(LindaGroup, int); |
| 17 | 17 | ||
| 18 | class Linda | 18 | class Linda final |
| 19 | : public DeepPrelude // Deep userdata MUST start with this header | 19 | : public DeepPrelude // Deep userdata MUST start with this header |
| 20 | { | 20 | { |
| 21 | public: | 21 | public: |
| 22 | class [[nodiscard]] KeeperOperationInProgress | 22 | class [[nodiscard]] KeeperOperationInProgress final |
| 23 | { | 23 | { |
| 24 | private: | 24 | private: |
| 25 | Linda& linda; | 25 | Linda& linda; |
diff --git a/src/lindafactory.hpp b/src/lindafactory.hpp index 0921c8f..814f21c 100644 --- a/src/lindafactory.hpp +++ b/src/lindafactory.hpp | |||
| @@ -4,13 +4,14 @@ | |||
| 4 | 4 | ||
| 5 | // ################################################################################################# | 5 | // ################################################################################################# |
| 6 | 6 | ||
| 7 | class LindaFactory | 7 | class LindaFactory final |
| 8 | : public DeepFactory | 8 | : public DeepFactory |
| 9 | { | 9 | { |
| 10 | public: | 10 | public: |
| 11 | // TODO: I'm not totally happy with having a 'global' variable. Maybe it should be dynamically created and stored somewhere in the universe? | 11 | // TODO: I'm not totally happy with having a 'global' variable. Maybe it should be dynamically created and stored somewhere in the universe? |
| 12 | static LindaFactory Instance; | 12 | static LindaFactory Instance; |
| 13 | 13 | ||
| 14 | ~LindaFactory() override = default; | ||
| 14 | LindaFactory(luaL_Reg const lindaMT_[]) | 15 | LindaFactory(luaL_Reg const lindaMT_[]) |
| 15 | : mLindaMT{ lindaMT_ } | 16 | : mLindaMT{ lindaMT_ } |
| 16 | { | 17 | { |
diff --git a/src/macros_and_utils.hpp b/src/macros_and_utils.hpp index 26d47a9..16011f7 100644 --- a/src/macros_and_utils.hpp +++ b/src/macros_and_utils.hpp | |||
| @@ -53,7 +53,7 @@ typename T::value_type const& OptionalValue(T const& x_, Ts... args_) | |||
| 53 | struct PasskeyToken {}; | 53 | struct PasskeyToken {}; |
| 54 | constexpr PasskeyToken PK{}; | 54 | constexpr PasskeyToken PK{}; |
| 55 | template <typename T> | 55 | template <typename T> |
| 56 | class Passkey | 56 | class Passkey final |
| 57 | { | 57 | { |
| 58 | private: | 58 | private: |
| 59 | friend T; | 59 | friend T; |
diff --git a/src/nameof.cpp b/src/nameof.cpp index 2ae315a..027c703 100644 --- a/src/nameof.cpp +++ b/src/nameof.cpp | |||
| @@ -33,7 +33,7 @@ THE SOFTWARE. | |||
| 33 | 33 | ||
| 34 | // Return some name helping to identify an object | 34 | // Return some name helping to identify an object |
| 35 | [[nodiscard]] | 35 | [[nodiscard]] |
| 36 | static int DiscoverObjectNameRecur(lua_State* L_, int shortest_, int depth_) | 36 | static int DiscoverObjectNameRecur(lua_State* const L_, int shortest_, TableIndex depth_) |
| 37 | { | 37 | { |
| 38 | static constexpr StackIndex kWhat{ 1 }; // the object to investigate // L_: o "r" {c} {fqn} ... {?} | 38 | static constexpr StackIndex kWhat{ 1 }; // the object to investigate // L_: o "r" {c} {fqn} ... {?} |
| 39 | static constexpr StackIndex kResult{ 2 }; // where the result string is stored | 39 | static constexpr StackIndex kResult{ 2 }; // where the result string is stored |
| @@ -193,13 +193,13 @@ LUAG_FUNC(nameof) | |||
| 193 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} | 193 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} |
| 194 | // this is where we start the search | 194 | // this is where we start the search |
| 195 | luaG_pushglobaltable(L_); // L_: o nil {c} {fqn} _G | 195 | luaG_pushglobaltable(L_); // L_: o nil {c} {fqn} _G |
| 196 | std::ignore = DiscoverObjectNameRecur(L_, std::numeric_limits<int>::max(), 1); | 196 | std::ignore = DiscoverObjectNameRecur(L_, std::numeric_limits<int>::max(), TableIndex{ 1 }); |
| 197 | if (lua_isnil(L_, 2)) { // try again with registry, just in case... | 197 | if (lua_isnil(L_, 2)) { // try again with registry, just in case... |
| 198 | lua_pop(L_, 1); // L_: o nil {c} {fqn} | 198 | lua_pop(L_, 1); // L_: o nil {c} {fqn} |
| 199 | luaG_pushstring(L_, "_R"); // L_: o nil {c} {fqn} "_R" | 199 | luaG_pushstring(L_, "_R"); // L_: o nil {c} {fqn} "_R" |
| 200 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} | 200 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} |
| 201 | lua_pushvalue(L_, kIdxRegistry); // L_: o nil {c} {fqn} _R | 201 | lua_pushvalue(L_, kIdxRegistry); // L_: o nil {c} {fqn} _R |
| 202 | std::ignore = DiscoverObjectNameRecur(L_, std::numeric_limits<int>::max(), 1); | 202 | std::ignore = DiscoverObjectNameRecur(L_, std::numeric_limits<int>::max(), TableIndex{ 1 }); |
| 203 | } | 203 | } |
| 204 | lua_pop(L_, 3); // L_: o "result" | 204 | lua_pop(L_, 3); // L_: o "result" |
| 205 | STACK_CHECK(L_, 1); | 205 | STACK_CHECK(L_, 1); |
diff --git a/src/stackindex.hpp b/src/stackindex.hpp index c414ce2..e7c1d8b 100644 --- a/src/stackindex.hpp +++ b/src/stackindex.hpp | |||
| @@ -5,6 +5,9 @@ | |||
| 5 | DECLARE_UNIQUE_TYPE(StackIndex, int); | 5 | DECLARE_UNIQUE_TYPE(StackIndex, int); |
| 6 | static_assert(std::is_trivial_v<StackIndex>); | 6 | static_assert(std::is_trivial_v<StackIndex>); |
| 7 | 7 | ||
| 8 | DECLARE_UNIQUE_TYPE(TableIndex, int); | ||
| 9 | static_assert(std::is_trivial_v<TableIndex>); | ||
| 10 | |||
| 8 | DECLARE_UNIQUE_TYPE(UserValueIndex, int); | 11 | DECLARE_UNIQUE_TYPE(UserValueIndex, int); |
| 9 | static_assert(std::is_trivial_v<UserValueIndex>); | 12 | static_assert(std::is_trivial_v<UserValueIndex>); |
| 10 | 13 | ||
| @@ -12,7 +15,7 @@ DECLARE_UNIQUE_TYPE(UserValueCount, int); | |||
| 12 | static_assert(std::is_trivial_v<UserValueCount>); | 15 | static_assert(std::is_trivial_v<UserValueCount>); |
| 13 | 16 | ||
| 14 | DECLARE_UNIQUE_TYPE(UnusedInt, int); | 17 | DECLARE_UNIQUE_TYPE(UnusedInt, int); |
| 15 | static_assert(std::is_trivial_v<UserValueCount>); | 18 | static_assert(std::is_trivial_v<UnusedInt>); |
| 16 | 19 | ||
| 17 | // ################################################################################################# | 20 | // ################################################################################################# |
| 18 | 21 | ||
diff --git a/src/state.cpp b/src/state.cpp index 88f406a..6fabc5f 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
| @@ -299,7 +299,7 @@ namespace state { | |||
| 299 | lua_pushvalue(_L, -5); // L: {} k v "[" 'k' "] = " tostring v | 299 | lua_pushvalue(_L, -5); // L: {} k v "[" 'k' "] = " tostring v |
| 300 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' "] = " 'v' | 300 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' "] = " 'v' |
| 301 | lua_concat(_L, 4); // L: {} k v "[k] = v" | 301 | lua_concat(_L, 4); // L: {} k v "[k] = v" |
| 302 | DEBUGSPEW_CODE(DebugSpew(U_) << luaG_tostring(_L, -1) << std::endl); | 302 | DEBUGSPEW_CODE(DebugSpew(U_) << luaG_tostring(_L, kIdxTop) << std::endl); |
| 303 | lua_pop(_L, 2); // L: {} k | 303 | lua_pop(_L, 2); // L: {} k |
| 304 | } // lua_next() // L: {} | 304 | } // lua_next() // L: {} |
| 305 | lua_pop(_L, 1); // L: | 305 | lua_pop(_L, 1); // L: |
diff --git a/src/tools.cpp b/src/tools.cpp index cd64d13..f3be85c 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
| @@ -47,7 +47,7 @@ static constexpr RegistryUniqueKey kLookupCacheRegKey{ 0x9BF75F84E54B691Bull }; | |||
| 47 | 47 | ||
| 48 | static constexpr int kWriterReturnCode{ 666 }; | 48 | static constexpr int kWriterReturnCode{ 666 }; |
| 49 | [[nodiscard]] | 49 | [[nodiscard]] |
| 50 | static int dummy_writer([[maybe_unused]] lua_State* L_, [[maybe_unused]] void const* p_, [[maybe_unused]] size_t sz_, [[maybe_unused]] void* ud_) | 50 | static int dummy_writer([[maybe_unused]] lua_State* const L_, [[maybe_unused]] void const* p_, [[maybe_unused]] size_t sz_, [[maybe_unused]] void* ud_) |
| 51 | { | 51 | { |
| 52 | // always fail with this code | 52 | // always fail with this code |
| 53 | return kWriterReturnCode; | 53 | return kWriterReturnCode; |
| @@ -93,13 +93,13 @@ FuncSubType luaG_getfuncsubtype(lua_State* const L_, StackIndex const i_) | |||
| 93 | namespace tools { | 93 | namespace tools { |
| 94 | 94 | ||
| 95 | // inspired from tconcat() in ltablib.c | 95 | // inspired from tconcat() in ltablib.c |
| 96 | std::string_view PushFQN(lua_State* const L_, StackIndex const t_, int const last_) | 96 | std::string_view PushFQN(lua_State* const L_, StackIndex const t_, TableIndex const last_) |
| 97 | { | 97 | { |
| 98 | STACK_CHECK_START_REL(L_, 0); | 98 | STACK_CHECK_START_REL(L_, 0); |
| 99 | // Lua 5.4 pushes &b as light userdata on the stack. be aware of it... | 99 | // Lua 5.4 pushes &b as light userdata on the stack. be aware of it... |
| 100 | luaL_Buffer _b; | 100 | luaL_Buffer _b; |
| 101 | luaL_buffinit(L_, &_b); // L_: ... {} ... &b? | 101 | luaL_buffinit(L_, &_b); // L_: ... {} ... &b? |
| 102 | int _i{ 1 }; | 102 | TableIndex _i{ 1 }; |
| 103 | for (; _i < last_; ++_i) { | 103 | for (; _i < last_; ++_i) { |
| 104 | lua_rawgeti(L_, t_, _i); | 104 | lua_rawgeti(L_, t_, _i); |
| 105 | luaL_addvalue(&_b); | 105 | luaL_addvalue(&_b); |
| @@ -127,7 +127,7 @@ namespace tools { | |||
| 127 | * if we already had an entry of type [o] = ..., replace the name if the new one is shorter | 127 | * if we already had an entry of type [o] = ..., replace the name if the new one is shorter |
| 128 | * pops the processed object from the stack | 128 | * pops the processed object from the stack |
| 129 | */ | 129 | */ |
| 130 | static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, int const depth_) | 130 | static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, TableIndex const depth_) |
| 131 | { | 131 | { |
| 132 | // slot 1 in the stack contains the table that receives everything we found | 132 | // slot 1 in the stack contains the table that receives everything we found |
| 133 | StackIndex const _dest{ ctxBase_ }; | 133 | StackIndex const _dest{ ctxBase_ }; |
| @@ -146,7 +146,7 @@ static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, | |||
| 146 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) | 146 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) |
| 147 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k | 147 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k |
| 148 | LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::NUMBER || luaG_type(L_, kIdxTop) == LuaType::STRING); | 148 | LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::NUMBER || luaG_type(L_, kIdxTop) == LuaType::STRING); |
| 149 | int const _deeper{ depth_ + 1 }; | 149 | TableIndex const _deeper{ depth_ + 1 }; |
| 150 | lua_rawseti(L_, _fqn, _deeper); // L_: ... {bfc} k o name? | 150 | lua_rawseti(L_, _fqn, _deeper); // L_: ... {bfc} k o name? |
| 151 | // generate name | 151 | // generate name |
| 152 | std::string_view const _newName{ tools::PushFQN(L_, _fqn, _deeper) }; // L_: ... {bfc} k o name? "f.q.n" | 152 | std::string_view const _newName{ tools::PushFQN(L_, _fqn, _deeper) }; // L_: ... {bfc} k o name? "f.q.n" |
| @@ -155,10 +155,10 @@ static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, | |||
| 155 | // Also, when Lua is built with compatibility options (such as LUA_COMPAT_ALL), some base libraries register functions under multiple names. | 155 | // Also, when Lua is built with compatibility options (such as LUA_COMPAT_ALL), some base libraries register functions under multiple names. |
| 156 | // This, with the randomizer, can cause the first generated name of an object to be different on different VMs, which breaks function transfer. | 156 | // This, with the randomizer, can cause the first generated name of an object to be different on different VMs, which breaks function transfer. |
| 157 | // Also, nothing prevents any external module from exposing a given object under several names, so... | 157 | // Also, nothing prevents any external module from exposing a given object under several names, so... |
| 158 | // Therefore, when we encounter an object for which a name was previously registered, we need to select the a single name | 158 | // Therefore, when we encounter an object for which a name was previously registered, we need to select a single name |
| 159 | // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded | 159 | // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded |
| 160 | if (!_prevName.empty() && ((_prevName.size() < _newName.size()) || (_prevName <= _newName))) { | 160 | if (!_prevName.empty() && ((_prevName.size() < _newName.size()) || (_prevName <= _newName))) { |
| 161 | DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, -3) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); | 161 | DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, StackIndex{ -3 }) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); |
| 162 | // the previous name is 'smaller' than the one we just generated: keep it! | 162 | // the previous name is 'smaller' than the one we just generated: keep it! |
| 163 | lua_pop(L_, 3); // L_: ... {bfc} k | 163 | lua_pop(L_, 3); // L_: ... {bfc} k |
| 164 | } else { | 164 | } else { |
| @@ -172,7 +172,7 @@ static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, | |||
| 172 | } else { | 172 | } else { |
| 173 | lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" | 173 | lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" |
| 174 | } | 174 | } |
| 175 | DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, -2) << " '" << _newName << "'" << std::endl); | 175 | DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, StackIndex{ -2 }) << " '" << _newName << "'" << std::endl); |
| 176 | // prepare the stack for database feed | 176 | // prepare the stack for database feed |
| 177 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" | 177 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" |
| 178 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o | 178 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o |
| @@ -191,7 +191,7 @@ static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, | |||
| 191 | 191 | ||
| 192 | // ################################################################################################# | 192 | // ################################################################################################# |
| 193 | 193 | ||
| 194 | static void populate_lookup_table_recur(lua_State* const L_, StackIndex const dbIdx_, StackIndex const i_, int const depth_) | 194 | static void populate_lookup_table_recur(lua_State* const L_, StackIndex const dbIdx_, StackIndex const i_, TableIndex const depth_) |
| 195 | { | 195 | { |
| 196 | // slot dbIdx_ contains the lookup database table | 196 | // slot dbIdx_ contains the lookup database table |
| 197 | // slot dbIdx_ + 1 contains a table that, when concatenated, produces the fully qualified name of scanned elements in the table provided at slot i_ | 197 | // slot dbIdx_ + 1 contains a table that, when concatenated, produces the fully qualified name of scanned elements in the table provided at slot i_ |
| @@ -267,10 +267,10 @@ static void populate_lookup_table_recur(lua_State* const L_, StackIndex const db | |||
| 267 | STACK_CHECK(L_, 2); | 267 | STACK_CHECK(L_, 2); |
| 268 | } | 268 | } |
| 269 | // now process the tables we encountered at that depth | 269 | // now process the tables we encountered at that depth |
| 270 | int const _deeper{ depth_ + 1 }; | 270 | TableIndex const _deeper{ depth_ + 1 }; |
| 271 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil | 271 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil |
| 272 | while (lua_next(L_, _breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} | 272 | while (lua_next(L_, _breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} |
| 273 | DEBUGSPEW_CODE(std::string_view const _key{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostring(L_, -2) : std::string_view{ "<not a string>" } }); | 273 | DEBUGSPEW_CODE(std::string_view const _key{ (luaG_type(L_, StackIndex{ -2 }) == LuaType::STRING) ? luaG_tostring(L_, StackIndex{ -2 }) : std::string_view{ "<not a string>" } }); |
| 274 | DEBUGSPEW_CODE(DebugSpew(_U) << "table '"<< _key <<"'" << std::endl); | 274 | DEBUGSPEW_CODE(DebugSpew(_U) << "table '"<< _key <<"'" << std::endl); |
| 275 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ _U }); | 275 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ _U }); |
| 276 | // un-visit this table in case we do need to process it | 276 | // un-visit this table in case we do need to process it |
| @@ -334,7 +334,7 @@ namespace tools { | |||
| 334 | lua_pop(L_, 1); // L_: | 334 | lua_pop(L_, 1); // L_: |
| 335 | } else if (luaG_type(L_, _in_base) == LuaType::TABLE) { | 335 | } else if (luaG_type(L_, _in_base) == LuaType::TABLE) { |
| 336 | lua_newtable(L_); // L_: {} {fqn} | 336 | lua_newtable(L_); // L_: {} {fqn} |
| 337 | int _startDepth{ 0 }; | 337 | TableIndex _startDepth{ 0 }; |
| 338 | if (!_name.empty()) { | 338 | if (!_name.empty()) { |
| 339 | STACK_CHECK(L_, 2); | 339 | STACK_CHECK(L_, 2); |
| 340 | luaG_pushstring(L_, _name); // L_: {} {fqn} "name" | 340 | luaG_pushstring(L_, _name); // L_: {} {fqn} "name" |
diff --git a/src/tools.hpp b/src/tools.hpp index 77ba5d2..9a62cda 100644 --- a/src/tools.hpp +++ b/src/tools.hpp | |||
| @@ -13,14 +13,13 @@ enum class LookupMode | |||
| 13 | 13 | ||
| 14 | // ################################################################################################# | 14 | // ################################################################################################# |
| 15 | 15 | ||
| 16 | enum class FuncSubType | 16 | enum class [[nodiscard]] FuncSubType |
| 17 | { | 17 | { |
| 18 | Bytecode, | 18 | Bytecode, |
| 19 | Native, | 19 | Native, |
| 20 | FastJIT | 20 | FastJIT |
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| 23 | [[nodiscard]] | ||
| 24 | FuncSubType luaG_getfuncsubtype(lua_State* L_, StackIndex i_); | 23 | FuncSubType luaG_getfuncsubtype(lua_State* L_, StackIndex i_); |
| 25 | 24 | ||
| 26 | // ################################################################################################# | 25 | // ################################################################################################# |
| @@ -36,6 +35,6 @@ static constexpr RegistryUniqueKey kLookupRegKey{ 0xBF1FC5CF3C6DD47Bull }; // re | |||
| 36 | namespace tools { | 35 | namespace tools { |
| 37 | void PopulateFuncLookupTable(lua_State* L_, StackIndex i_, std::string_view const& name_); | 36 | void PopulateFuncLookupTable(lua_State* L_, StackIndex i_, std::string_view const& name_); |
| 38 | [[nodiscard]] | 37 | [[nodiscard]] |
| 39 | std::string_view PushFQN(lua_State* L_, StackIndex t_, int last_); | 38 | std::string_view PushFQN(lua_State* L_, StackIndex t_, TableIndex last_); |
| 40 | void SerializeRequire(lua_State* L_); | 39 | void SerializeRequire(lua_State* L_); |
| 41 | } // namespace tools | 40 | } // namespace tools |
diff --git a/src/unique.hpp b/src/unique.hpp index aec5610..06a4532 100644 --- a/src/unique.hpp +++ b/src/unique.hpp | |||
| @@ -78,7 +78,7 @@ class [[nodiscard]] Unique<T, TAG, std::enable_if_t<!std::is_scalar_v<T>>> | |||
| 78 | using self = Unique<T, TAG, void>; | 78 | using self = Unique<T, TAG, void>; |
| 79 | using type = T; | 79 | using type = T; |
| 80 | using T::T; | 80 | using T::T; |
| 81 | explicit Unique(T const& b_) | 81 | constexpr explicit Unique(T const& b_) |
| 82 | : T{ b_ } | 82 | : T{ b_ } |
| 83 | { | 83 | { |
| 84 | } | 84 | } |
diff --git a/src/uniquekey.hpp b/src/uniquekey.hpp index 3006b3d..4c9eb58 100644 --- a/src/uniquekey.hpp +++ b/src/uniquekey.hpp | |||
| @@ -48,7 +48,7 @@ class UniqueKey | |||
| 48 | DECLARE_UNIQUE_TYPE(NArr, int); | 48 | DECLARE_UNIQUE_TYPE(NArr, int); |
| 49 | DECLARE_UNIQUE_TYPE(NRec, int); | 49 | DECLARE_UNIQUE_TYPE(NRec, int); |
| 50 | 50 | ||
| 51 | class RegistryUniqueKey | 51 | class RegistryUniqueKey final |
| 52 | : public UniqueKey | 52 | : public UniqueKey |
| 53 | { | 53 | { |
| 54 | public: | 54 | public: |
diff --git a/src/universe.hpp b/src/universe.hpp index d35172d..75604d8 100644 --- a/src/universe.hpp +++ b/src/universe.hpp | |||
| @@ -16,7 +16,7 @@ class Linda; | |||
| 16 | // ################################################################################################# | 16 | // ################################################################################################# |
| 17 | 17 | ||
| 18 | // mutex-protected allocator for use with Lua states that share a non-threadsafe allocator | 18 | // mutex-protected allocator for use with Lua states that share a non-threadsafe allocator |
| 19 | class ProtectedAllocator | 19 | class ProtectedAllocator final |
| 20 | : public lanes::AllocatorDefinition | 20 | : public lanes::AllocatorDefinition |
| 21 | { | 21 | { |
| 22 | private: | 22 | private: |
| @@ -67,7 +67,7 @@ static constexpr RegistryUniqueKey kUniverseLightRegKey{ 0x48BBE9CEAB0BA04Full } | |||
| 67 | 67 | ||
| 68 | // everything regarding the Lanes universe is stored in that global structure | 68 | // everything regarding the Lanes universe is stored in that global structure |
| 69 | // held as a full userdata in the master Lua state that required it for the first time | 69 | // held as a full userdata in the master Lua state that required it for the first time |
| 70 | class Universe | 70 | class Universe final |
| 71 | { | 71 | { |
| 72 | public: | 72 | public: |
| 73 | static constexpr char const* kFinally{ "finally" }; // update lanes.lua if the name changes! | 73 | static constexpr char const* kFinally{ "finally" }; // update lanes.lua if the name changes! |
