aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-10-24 14:37:17 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-10-24 14:37:17 +0200
commit958ed4f1e29418e90f3dd3de6779e30e05f70448 (patch)
tree01f42e0fa04b3fd806accfdc6d912fc7f99cd12f
parenteba98e4e1adcf3ce11e5934e2dce54f29aef1e0a (diff)
downloadlanes-958ed4f1e29418e90f3dd3de6779e30e05f70448.tar.gz
lanes-958ed4f1e29418e90f3dd3de6779e30e05f70448.tar.bz2
lanes-958ed4f1e29418e90f3dd3de6779e30e05f70448.zip
More strong typing for UniqueKey::getSubTable() arguments
-rw-r--r--src/deep.cpp2
-rw-r--r--src/intercopycontext.cpp4
-rw-r--r--src/lane.cpp2
-rw-r--r--src/tools.cpp2
-rw-r--r--src/uniquekey.h7
5 files changed, 10 insertions, 7 deletions
diff --git a/src/deep.cpp b/src/deep.cpp
index 0d801a3..bfadeac 100644
--- a/src/deep.cpp
+++ b/src/deep.cpp
@@ -342,7 +342,7 @@ void DeepFactory::storeDeepLookup(lua_State* const L_) const
342 // the deep metatable is at the top of the stack // L_: mt 342 // the deep metatable is at the top of the stack // L_: mt
343 STACK_GROW(L_, 3); 343 STACK_GROW(L_, 3);
344 STACK_CHECK_START_REL(L_, 0); // L_: mt 344 STACK_CHECK_START_REL(L_, 0); // L_: mt
345 std::ignore = kDeepLookupRegKey.getSubTable(L_, 0, 0); // L_: mt {} 345 std::ignore = kDeepLookupRegKey.getSubTable(L_, NArr{ 0 }, NRec{ 0 }); // L_: mt {}
346 lua_pushvalue(L_, -2); // L_: mt {} mt 346 lua_pushvalue(L_, -2); // L_: mt {} mt
347 lua_pushlightuserdata(L_, std::bit_cast<void*>(this)); // L_: mt {} mt factory 347 lua_pushlightuserdata(L_, std::bit_cast<void*>(this)); // L_: mt {} mt factory
348 lua_rawset(L_, -3); // L_: mt {} 348 lua_rawset(L_, -3); // L_: mt {}
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp
index 5f3ce7d..7244ed8 100644
--- a/src/intercopycontext.cpp
+++ b/src/intercopycontext.cpp
@@ -148,7 +148,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull };
148 STACK_GROW(L_, 3); 148 STACK_GROW(L_, 3);
149 149
150 STACK_CHECK_START_REL(L_, 0); 150 STACK_CHECK_START_REL(L_, 0);
151 std::ignore = kMtIdRegKey.getSubTable(L_, 0, 0); // L_: ... _R[kMtIdRegKey] 151 std::ignore = kMtIdRegKey.getSubTable(L_, NArr{ 0 }, NRec{ 0 }); // L_: ... _R[kMtIdRegKey]
152 lua_pushvalue(L_, _absidx); // L_: ... _R[kMtIdRegKey] {mt} 152 lua_pushvalue(L_, _absidx); // L_: ... _R[kMtIdRegKey] {mt}
153 lua_rawget(L_, -2); // L_: ... _R[kMtIdRegKey] mtk? 153 lua_rawget(L_, -2); // L_: ... _R[kMtIdRegKey] mtk?
154 154
@@ -599,7 +599,7 @@ LuaType InterCopyContext::processConversion() const
599 STACK_CHECK_START_REL(L2, 0); 599 STACK_CHECK_START_REL(L2, 0);
600 STACK_GROW(L2, 4); 600 STACK_GROW(L2, 4);
601 // do we already know this metatable? 601 // do we already know this metatable?
602 std::ignore = kMtIdRegKey.getSubTable(L2, 0, 0); // L2: _R[kMtIdRegKey] 602 std::ignore = kMtIdRegKey.getSubTable(L2, NArr{ 0 }, NRec{ 0 }); // L2: _R[kMtIdRegKey]
603 lua_pushinteger(L2, _mt_id); // L2: _R[kMtIdRegKey] id 603 lua_pushinteger(L2, _mt_id); // L2: _R[kMtIdRegKey] id
604 lua_rawget(L2, -2); // L2: _R[kMtIdRegKey] mt|nil 604 lua_rawget(L2, -2); // L2: _R[kMtIdRegKey] mt|nil
605 STACK_CHECK(L2, 2); 605 STACK_CHECK(L2, 2);
diff --git a/src/lane.cpp b/src/lane.cpp
index d4d409f..29ad8bb 100644
--- a/src/lane.cpp
+++ b/src/lane.cpp
@@ -68,7 +68,7 @@ static LUAG_FUNC(set_finalizer)
68 luaL_argcheck(L_, lua_gettop(L_) == 1, 1, "too many arguments"); 68 luaL_argcheck(L_, lua_gettop(L_) == 1, 1, "too many arguments");
69 STACK_GROW(L_, 3); 69 STACK_GROW(L_, 3);
70 // Get the current finalizer table (if any), create one if it doesn't exist 70 // Get the current finalizer table (if any), create one if it doesn't exist
71 std::ignore = kFinalizerRegKey.getSubTable(L_, 1, 0); // L_: finalizer {finalisers} 71 std::ignore = kFinalizerRegKey.getSubTable(L_, NArr{ 1 }, NRec{ 0 }); // L_: finalizer {finalisers}
72 // must cast to int, not lua_Integer, because LuaJIT signature of lua_rawseti is not the same as PUC-Lua. 72 // must cast to int, not lua_Integer, because LuaJIT signature of lua_rawseti is not the same as PUC-Lua.
73 int const _idx{ static_cast<int>(lua_rawlen(L_, kIdxTop) + 1) }; 73 int const _idx{ static_cast<int>(lua_rawlen(L_, kIdxTop) + 1) };
74 lua_pushvalue(L_, 1); // L_: finalizer {finalisers} finalizer 74 lua_pushvalue(L_, 1); // L_: finalizer {finalisers} finalizer
diff --git a/src/tools.cpp b/src/tools.cpp
index d0204a6..34b9faf 100644
--- a/src/tools.cpp
+++ b/src/tools.cpp
@@ -340,7 +340,7 @@ namespace tools {
340 STACK_CHECK(L_, 2); 340 STACK_CHECK(L_, 2);
341 } 341 }
342 // retrieve the cache, create it if we haven't done it yet 342 // retrieve the cache, create it if we haven't done it yet
343 std::ignore = kLookupCacheRegKey.getSubTable(L_, 0, 0); // L_: {} {fqn} {cache} 343 std::ignore = kLookupCacheRegKey.getSubTable(L_, NArr{ 0 }, NRec{ 0 }); // L_: {} {fqn} {cache}
344 // process everything we find in that table, filling in lookup data for all functions and tables we see there 344 // process everything we find in that table, filling in lookup data for all functions and tables we see there
345 populate_func_lookup_table_recur(L_, _dbIdx, _in_base, _startDepth); 345 populate_func_lookup_table_recur(L_, _dbIdx, _in_base, _startDepth);
346 lua_pop(L_, 3); // L_: 346 lua_pop(L_, 3); // L_:
diff --git a/src/uniquekey.h b/src/uniquekey.h
index c409048..ddc157b 100644
--- a/src/uniquekey.h
+++ b/src/uniquekey.h
@@ -45,6 +45,9 @@ class UniqueKey
45 45
46// ################################################################################################# 46// #################################################################################################
47 47
48DECLARE_UNIQUE_TYPE(NArr, int);
49DECLARE_UNIQUE_TYPE(NRec, int);
50
48class RegistryUniqueKey 51class RegistryUniqueKey
49: public UniqueKey 52: public UniqueKey
50{ 53{
@@ -93,7 +96,7 @@ class RegistryUniqueKey
93 } 96 }
94 // --------------------------------------------------------------------------------------------- 97 // ---------------------------------------------------------------------------------------------
95 // equivalent to luaL_getsubtable 98 // equivalent to luaL_getsubtable
96 [[nodiscard]] bool getSubTable(lua_State* const L_, int const narr_, int const nrec_) const 99 [[nodiscard]] bool getSubTable(lua_State* const L_, NArr const narr_, NRec const nrec_) const
97 { 100 {
98 STACK_CHECK_START_REL(L_, 0); 101 STACK_CHECK_START_REL(L_, 0);
99 pushValue(L_); // L_: {}|nil 102 pushValue(L_); // L_: {}|nil
@@ -113,7 +116,7 @@ class RegistryUniqueKey
113 void getSubTableMode(lua_State* const L_, std::string_view const& mode_) const 116 void getSubTableMode(lua_State* const L_, std::string_view const& mode_) const
114 { 117 {
115 STACK_CHECK_START_REL(L_, 0); 118 STACK_CHECK_START_REL(L_, 0);
116 if (!getSubTable(L_, 0, 0)) { // L_: {} 119 if (!getSubTable(L_, NArr{ 0 }, NRec{ 0 })) { // L_: {}
117 // Set its metatable if requested 120 // Set its metatable if requested
118 if (!mode_.empty()) { 121 if (!mode_.empty()) {
119 STACK_GROW(L_, 3); 122 STACK_GROW(L_, 3);