diff options
Diffstat (limited to '')
-rw-r--r-- | src/tools.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
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" |