diff options
Diffstat (limited to '')
-rw-r--r-- | src/tools.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/tools.cpp b/src/tools.cpp index ee6d720..cbfefb0 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -95,19 +95,20 @@ namespace tools { | |||
95 | 95 | ||
96 | // inspired from tconcat() in ltablib.c | 96 | // inspired from tconcat() in ltablib.c |
97 | [[nodiscard]] | 97 | [[nodiscard]] |
98 | std::string_view PushFQN(lua_State* const L_, StackIndex const t_, TableIndex const last_) | 98 | std::string_view PushFQN(lua_State* const L_, StackIndex const t_) |
99 | { | 99 | { |
100 | STACK_CHECK_START_REL(L_, 0); | 100 | STACK_CHECK_START_REL(L_, 0); |
101 | // Lua 5.4 pushes &b as light userdata on the stack. be aware of it... | 101 | // Lua 5.4 pushes &b as light userdata on the stack. be aware of it... |
102 | luaL_Buffer _b; | 102 | luaL_Buffer _b; |
103 | luaL_buffinit(L_, &_b); // L_: ... {} ... &b? | 103 | luaL_buffinit(L_, &_b); // L_: ... {} ... &b? |
104 | TableIndex _i{ 1 }; | 104 | TableIndex _i{ 1 }; |
105 | for (; _i < last_; ++_i) { | 105 | TableIndex const _last{ static_cast<TableIndex::type>(lua_rawlen(L_, t_)) }; |
106 | for (; _i < _last; ++_i) { | ||
106 | lua_rawgeti(L_, t_, _i); | 107 | lua_rawgeti(L_, t_, _i); |
107 | luaL_addvalue(&_b); | 108 | luaL_addvalue(&_b); |
108 | luaL_addlstring(&_b, "/", 1); | 109 | luaL_addlstring(&_b, "/", 1); |
109 | } | 110 | } |
110 | if (_i == last_) { // add last value (if interval was not empty) | 111 | if (_i == _last) { // add last value (if interval was not empty) |
111 | lua_rawgeti(L_, t_, _i); | 112 | lua_rawgeti(L_, t_, _i); |
112 | luaL_addvalue(&_b); | 113 | luaL_addvalue(&_b); |
113 | } | 114 | } |
@@ -151,7 +152,7 @@ static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, | |||
151 | TableIndex const _deeper{ depth_ + 1 }; | 152 | TableIndex const _deeper{ depth_ + 1 }; |
152 | lua_rawseti(L_, _fqn, _deeper); // L_: ... {bfc} k o name? | 153 | lua_rawseti(L_, _fqn, _deeper); // L_: ... {bfc} k o name? |
153 | // generate name | 154 | // generate name |
154 | std::string_view const _newName{ tools::PushFQN(L_, _fqn, _deeper) }; // L_: ... {bfc} k o name? "f.q.n" | 155 | std::string_view const _newName{ tools::PushFQN(L_, _fqn) }; // L_: ... {bfc} k o name? "f.q.n" |
155 | // Lua 5.2 introduced a hash randomizer seed which causes table iteration to yield a different key order | 156 | // Lua 5.2 introduced a hash randomizer seed which causes table iteration to yield a different key order |
156 | // on different VMs even when the tables are populated the exact same way. | 157 | // on different VMs even when the tables are populated the exact same way. |
157 | // Also, when Lua is built with compatibility options (such as LUA_COMPAT_ALL), some base libraries register functions under multiple names. | 158 | // Also, when Lua is built with compatibility options (such as LUA_COMPAT_ALL), some base libraries register functions under multiple names. |