diff options
Diffstat (limited to 'src/tools.cpp')
-rw-r--r-- | src/tools.cpp | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/src/tools.cpp b/src/tools.cpp index 2623da6..0cfe1ab 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -69,16 +69,16 @@ static constexpr RegistryUniqueKey kLookupCacheRegKey{ 0x9BF75F84E54B691Bull }; | |||
69 | return FuncSubType::Native; | 69 | return FuncSubType::Native; |
70 | } | 70 | } |
71 | { | 71 | { |
72 | int mustpush{ 0 }; | 72 | int _mustpush{ 0 }; |
73 | if (lua_absindex(L_, _i) != lua_gettop(L_)) { | 73 | if (lua_absindex(L_, _i) != lua_gettop(L_)) { |
74 | lua_pushvalue(L_, _i); | 74 | lua_pushvalue(L_, _i); |
75 | mustpush = 1; | 75 | _mustpush = 1; |
76 | } | 76 | } |
77 | // the provided writer fails with code 666 | 77 | // the provided writer fails with code 666 |
78 | // therefore, anytime we get 666, this means that lua_dump() attempted a dump | 78 | // therefore, anytime we get 666, this means that lua_dump() attempted a dump |
79 | // all other cases mean this is either a C or LuaJIT-fast function | 79 | // all other cases mean this is either a C or LuaJIT-fast function |
80 | int const dumpres{ lua504_dump(L_, dummy_writer, nullptr, 0) }; | 80 | int const dumpres{ lua504_dump(L_, dummy_writer, nullptr, 0) }; |
81 | lua_pop(L_, mustpush); | 81 | lua_pop(L_, _mustpush); |
82 | if (dumpres == 666) { | 82 | if (dumpres == 666) { |
83 | return FuncSubType::Bytecode; | 83 | return FuncSubType::Bytecode; |
84 | } | 84 | } |
@@ -91,22 +91,22 @@ static constexpr RegistryUniqueKey kLookupCacheRegKey{ 0x9BF75F84E54B691Bull }; | |||
91 | // inspired from tconcat() in ltablib.c | 91 | // inspired from tconcat() in ltablib.c |
92 | [[nodiscard]] static char const* luaG_pushFQN(lua_State* L_, int t_, int last_, size_t* length_) | 92 | [[nodiscard]] static char const* luaG_pushFQN(lua_State* L_, int t_, int last_, size_t* length_) |
93 | { | 93 | { |
94 | luaL_Buffer b; | 94 | luaL_Buffer _b; |
95 | STACK_CHECK_START_REL(L_, 0); | 95 | STACK_CHECK_START_REL(L_, 0); |
96 | // Lua 5.4 pushes &b as light userdata on the stack. be aware of it... | 96 | // Lua 5.4 pushes &b as light userdata on the stack. be aware of it... |
97 | luaL_buffinit(L_, &b); // L_: ... {} ... &b? | 97 | luaL_buffinit(L_, &_b); // L_: ... {} ... &b? |
98 | int i = 1; | 98 | int i = 1; |
99 | for (; i < last_; ++i) { | 99 | for (; i < last_; ++i) { |
100 | lua_rawgeti(L_, t_, i); | 100 | lua_rawgeti(L_, t_, i); |
101 | luaL_addvalue(&b); | 101 | luaL_addvalue(&_b); |
102 | luaL_addlstring(&b, "/", 1); | 102 | luaL_addlstring(&_b, "/", 1); |
103 | } | 103 | } |
104 | if (i == last_) { // add last value (if interval was not empty) | 104 | if (i == last_) { // add last value (if interval was not empty) |
105 | lua_rawgeti(L_, t_, i); | 105 | lua_rawgeti(L_, t_, i); |
106 | luaL_addvalue(&b); | 106 | luaL_addvalue(&_b); |
107 | } | 107 | } |
108 | // &b is popped at that point (-> replaced by the result) | 108 | // &b is popped at that point (-> replaced by the result) |
109 | luaL_pushresult(&b); // L_: ... {} ... "<result>" | 109 | luaL_pushresult(&_b); // L_: ... {} ... "<result>" |
110 | STACK_CHECK(L_, 1); | 110 | STACK_CHECK(L_, 1); |
111 | return lua_tolstring(L_, -1, length_); | 111 | return lua_tolstring(L_, -1, length_); |
112 | } | 112 | } |
@@ -124,28 +124,28 @@ static constexpr RegistryUniqueKey kLookupCacheRegKey{ 0x9BF75F84E54B691Bull }; | |||
124 | static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L_, int ctxBase_, int depth_) | 124 | static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L_, int ctxBase_, int depth_) |
125 | { | 125 | { |
126 | // slot 1 in the stack contains the table that receives everything we found | 126 | // slot 1 in the stack contains the table that receives everything we found |
127 | int const dest{ ctxBase_ }; | 127 | int const _dest{ ctxBase_ }; |
128 | // slot 2 contains a table that, when concatenated, produces the fully qualified name of scanned elements in the table provided at slot _i | 128 | // slot 2 contains a table that, when concatenated, produces the fully qualified name of scanned elements in the table provided at slot _i |
129 | int const fqn{ ctxBase_ + 1 }; | 129 | int const _fqn{ ctxBase_ + 1 }; |
130 | 130 | ||
131 | size_t prevNameLength, newNameLength; | 131 | DEBUGSPEW_CODE(char const* _newName); |
132 | char const* prevName; | ||
133 | DEBUGSPEW_CODE(char const* newName); | ||
134 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "update_lookup_entry()\n" INDENT_END(U_))); | 132 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "update_lookup_entry()\n" INDENT_END(U_))); |
135 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U_ }); | 133 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U_ }); |
136 | 134 | ||
137 | STACK_CHECK_START_REL(L_, 0); | 135 | STACK_CHECK_START_REL(L_, 0); |
138 | // first, raise an error if the function is already known | 136 | // first, raise an error if the function is already known |
139 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o o | 137 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o o |
140 | lua_rawget(L_, dest); // L_: ... {bfc} k o name? | 138 | lua_rawget(L_, _dest); // L_: ... {bfc} k o name? |
141 | prevName = lua_tolstring(L_, -1, &prevNameLength); // nullptr if we got nil (first encounter of this object) | 139 | size_t _prevNameLength; |
140 | char const* const _prevName{ lua_tolstring(L_, -1, &_prevNameLength) }; // nullptr if we got nil (first encounter of this object) | ||
142 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) | 141 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) |
143 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k | 142 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k |
144 | LUA_ASSERT(L_, lua_type(L_, -1) == LUA_TNUMBER || lua_type(L_, -1) == LUA_TSTRING); | 143 | LUA_ASSERT(L_, lua_type(L_, -1) == LUA_TNUMBER || lua_type(L_, -1) == LUA_TSTRING); |
145 | ++depth_; | 144 | ++depth_; |
146 | lua_rawseti(L_, fqn, depth_); // L_: ... {bfc} k o name? | 145 | lua_rawseti(L_, _fqn, depth_); // L_: ... {bfc} k o name? |
147 | // generate name | 146 | // generate name |
148 | DEBUGSPEW_OR_NOT(newName, std::ignore) = luaG_pushFQN(L_, fqn, depth_, &newNameLength); // L_: ... {bfc} k o name? "f.q.n" | 147 | size_t _newNameLength; |
148 | DEBUGSPEW_OR_NOT(_newName, std::ignore) = luaG_pushFQN(L_, _fqn, depth_, &_newNameLength); // L_: ... {bfc} k o name? "f.q.n" | ||
149 | // Lua 5.2 introduced a hash randomizer seed which causes table iteration to yield a different key order | 149 | // Lua 5.2 introduced a hash randomizer seed which causes table iteration to yield a different key order |
150 | // on different VMs even when the tables are populated the exact same way. | 150 | // on different VMs even when the tables are populated the exact same way. |
151 | // When Lua is built with compatibility options (such as LUA_COMPAT_ALL), | 151 | // When Lua is built with compatibility options (such as LUA_COMPAT_ALL), |
@@ -155,34 +155,34 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L | |||
155 | // Also, nothing prevents any external module from exposing a given object under several names, so... | 155 | // Also, nothing prevents any external module from exposing a given object under several names, so... |
156 | // Therefore, when we encounter an object for which a name was previously registered, we need to select the names | 156 | // Therefore, when we encounter an object for which a name was previously registered, we need to select the names |
157 | // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded | 157 | // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded |
158 | if (prevName != nullptr && (prevNameLength < newNameLength || lua_lessthan(L_, -2, -1))) { | 158 | if (_prevName != nullptr && (_prevNameLength < _newNameLength || lua_lessthan(L_, -2, -1))) { |
159 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s '%s' remained named '%s'\n" INDENT_END(U_), lua_typename(L_, lua_type(L_, -3)), newName, prevName)); | 159 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s '%s' remained named '%s'\n" INDENT_END(U_), lua_typename(L_, lua_type(L_, -3)), _newName, _prevName)); |
160 | // the previous name is 'smaller' than the one we just generated: keep it! | 160 | // the previous name is 'smaller' than the one we just generated: keep it! |
161 | lua_pop(L_, 3); // L_: ... {bfc} k | 161 | lua_pop(L_, 3); // L_: ... {bfc} k |
162 | } else { | 162 | } else { |
163 | // the name we generated is either the first one, or a better fit for our purposes | 163 | // the name we generated is either the first one, or a better fit for our purposes |
164 | if (prevName) { | 164 | if (_prevName) { |
165 | // clear the previous name for the database to avoid clutter | 165 | // clear the previous name for the database to avoid clutter |
166 | lua_insert(L_, -2); // L_: ... {bfc} k o "f.q.n" prevName | 166 | lua_insert(L_, -2); // L_: ... {bfc} k o "f.q.n" prevName |
167 | // t[prevName] = nil | 167 | // t[prevName] = nil |
168 | lua_pushnil(L_); // L_: ... {bfc} k o "f.q.n" prevName nil | 168 | lua_pushnil(L_); // L_: ... {bfc} k o "f.q.n" prevName nil |
169 | lua_rawset(L_, dest); // L_: ... {bfc} k o "f.q.n" | 169 | lua_rawset(L_, _dest); // L_: ... {bfc} k o "f.q.n" |
170 | } else { | 170 | } else { |
171 | lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" | 171 | lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" |
172 | } | 172 | } |
173 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s '%s'\n" INDENT_END(U_), lua_typename(L_, lua_type(L_, -2)), newName)); | 173 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s '%s'\n" INDENT_END(U_), lua_typename(L_, lua_type(L_, -2)), _newName)); |
174 | // prepare the stack for database feed | 174 | // prepare the stack for database feed |
175 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" | 175 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" |
176 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o | 176 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o |
177 | LUA_ASSERT(L_, lua_rawequal(L_, -1, -4)); | 177 | LUA_ASSERT(L_, lua_rawequal(L_, -1, -4)); |
178 | LUA_ASSERT(L_, lua_rawequal(L_, -2, -3)); | 178 | LUA_ASSERT(L_, lua_rawequal(L_, -2, -3)); |
179 | // t["f.q.n"] = o | 179 | // t["f.q.n"] = o |
180 | lua_rawset(L_, dest); // L_: ... {bfc} k o "f.q.n" | 180 | lua_rawset(L_, _dest); // L_: ... {bfc} k o "f.q.n" |
181 | // t[o] = "f.q.n" | 181 | // t[o] = "f.q.n" |
182 | lua_rawset(L_, dest); // L_: ... {bfc} k | 182 | lua_rawset(L_, _dest); // L_: ... {bfc} k |
183 | // remove table name from fqn stack | 183 | // remove table name from fqn stack |
184 | lua_pushnil(L_); // L_: ... {bfc} k nil | 184 | lua_pushnil(L_); // L_: ... {bfc} k nil |
185 | lua_rawseti(L_, fqn, depth_); // L_: ... {bfc} k | 185 | lua_rawseti(L_, _fqn, depth_); // L_: ... {bfc} k |
186 | } | 186 | } |
187 | --depth_; | 187 | --depth_; |
188 | STACK_CHECK(L_, -1); | 188 | STACK_CHECK(L_, -1); |
@@ -194,9 +194,9 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) | |||
194 | { | 194 | { |
195 | // slot dbIdx_ contains the lookup database table | 195 | // slot dbIdx_ contains the lookup database table |
196 | // slot dbIdx_ + 1 contains a table that, when concatenated, produces the fully qualified name of scanned elements in the table provided at slot i_ | 196 | // 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 | int const fqn{ dbIdx_ + 1 }; | 197 | int const _fqn{ dbIdx_ + 1 }; |
198 | // slot dbIdx_ + 2 contains a cache that stores all already visited tables to avoid infinite recursion loops | 198 | // slot dbIdx_ + 2 contains a cache that stores all already visited tables to avoid infinite recursion loops |
199 | int const cache{ dbIdx_ + 2 }; | 199 | int const _cache{ dbIdx_ + 2 }; |
200 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "populate_func_lookup_table_recur()\n" INDENT_END(U_))); | 200 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "populate_func_lookup_table_recur()\n" INDENT_END(U_))); |
201 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U_ }); | 201 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U_ }); |
202 | 202 | ||
@@ -212,19 +212,19 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) | |||
212 | 212 | ||
213 | // if table is already visited, we are done | 213 | // if table is already visited, we are done |
214 | lua_pushvalue(L_, i_); // L_: ... {i_} {} | 214 | lua_pushvalue(L_, i_); // L_: ... {i_} {} |
215 | lua_rawget(L_, cache); // L_: ... {i_} nil|n | 215 | lua_rawget(L_, _cache); // L_: ... {i_} nil|n |
216 | lua_Integer visit_count{ lua_tointeger(L_, -1) }; // 0 if nil, else n | 216 | lua_Integer _visit_count{ lua_tointeger(L_, -1) }; // 0 if nil, else n |
217 | lua_pop(L_, 1); // L_: ... {i_} | 217 | lua_pop(L_, 1); // L_: ... {i_} |
218 | STACK_CHECK(L_, 0); | 218 | STACK_CHECK(L_, 0); |
219 | if (visit_count > 0) { | 219 | if (_visit_count > 0) { |
220 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "already visited\n" INDENT_END(U_))); | 220 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "already visited\n" INDENT_END(U_))); |
221 | return; | 221 | return; |
222 | } | 222 | } |
223 | 223 | ||
224 | // remember we visited this table (1-visit count) | 224 | // remember we visited this table (1-visit count) |
225 | lua_pushvalue(L_, i_); // L_: ... {i_} {} | 225 | lua_pushvalue(L_, i_); // L_: ... {i_} {} |
226 | lua_pushinteger(L_, visit_count + 1); // L_: ... {i_} {} 1 | 226 | lua_pushinteger(L_, _visit_count + 1); // L_: ... {i_} {} 1 |
227 | lua_rawset(L_, cache); // L_: ... {i_} | 227 | lua_rawset(L_, _cache); // L_: ... {i_} |
228 | STACK_CHECK(L_, 0); | 228 | STACK_CHECK(L_, 0); |
229 | 229 | ||
230 | // we need to remember subtables to process them after functions encountered at the current depth (breadth-first search) | 230 | // we need to remember subtables to process them after functions encountered at the current depth (breadth-first search) |
@@ -240,11 +240,11 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) | |||
240 | // increment visit count to make sure we will actually scan it at this recursive level | 240 | // increment visit count to make sure we will actually scan it at this recursive level |
241 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} | 241 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} |
242 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} {} | 242 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} {} |
243 | lua_rawget(L_, cache); // L_: ... {i_} {bfc} k {} {} n? | 243 | lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} {} n? |
244 | visit_count = lua_tointeger(L_, -1) + 1; // 1 if we got nil, else n+1 | 244 | _visit_count = lua_tointeger(L_, -1) + 1; // 1 if we got nil, else n+1 |
245 | lua_pop(L_, 1); // L_: ... {i_} {bfc} k {} {} | 245 | lua_pop(L_, 1); // L_: ... {i_} {bfc} k {} {} |
246 | lua_pushinteger(L_, visit_count); // L_: ... {i_} {bfc} k {} {} n | 246 | lua_pushinteger(L_, _visit_count); // L_: ... {i_} {bfc} k {} {} n |
247 | lua_rawset(L_, cache); // L_: ... {i_} {bfc} k {} | 247 | lua_rawset(L_, _cache); // L_: ... {i_} {bfc} k {} |
248 | // store the table in the breadth-first cache | 248 | // store the table in the breadth-first cache |
249 | lua_pushvalue(L_, -2); // L_: ... {i_} {bfc} k {} k | 249 | lua_pushvalue(L_, -2); // L_: ... {i_} {bfc} k {} k |
250 | lua_pushvalue(L_, -2); // L_: ... {i_} {bfc} k {} k {} | 250 | lua_pushvalue(L_, -2); // L_: ... {i_} {bfc} k {} k {} |
@@ -269,27 +269,27 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) | |||
269 | DEBUGSPEW_CODE(DebugSpewIndentScope scope2{ U_ }); | 269 | DEBUGSPEW_CODE(DebugSpewIndentScope scope2{ U_ }); |
270 | // un-visit this table in case we do need to process it | 270 | // un-visit this table in case we do need to process it |
271 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} | 271 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} |
272 | lua_rawget(L_, cache); // L_: ... {i_} {bfc} k {} n | 272 | lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} n |
273 | LUA_ASSERT(L_, lua_type(L_, -1) == LUA_TNUMBER); | 273 | LUA_ASSERT(L_, lua_type(L_, -1) == LUA_TNUMBER); |
274 | visit_count = lua_tointeger(L_, -1) - 1; | 274 | _visit_count = lua_tointeger(L_, -1) - 1; |
275 | lua_pop(L_, 1); // L_: ... {i_} {bfc} k {} | 275 | lua_pop(L_, 1); // L_: ... {i_} {bfc} k {} |
276 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} | 276 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} |
277 | if (visit_count > 0) { | 277 | if (_visit_count > 0) { |
278 | lua_pushinteger(L_, visit_count); // L_: ... {i_} {bfc} k {} {} n | 278 | lua_pushinteger(L_, _visit_count); // L_: ... {i_} {bfc} k {} {} n |
279 | } else { | 279 | } else { |
280 | lua_pushnil(L_); // L_: ... {i_} {bfc} k {} {} nil | 280 | lua_pushnil(L_); // L_: ... {i_} {bfc} k {} {} nil |
281 | } | 281 | } |
282 | lua_rawset(L_, cache); // L_: ... {i_} {bfc} k {} | 282 | lua_rawset(L_, _cache); // L_: ... {i_} {bfc} k {} |
283 | // push table name in fqn stack (note that concatenation will crash if name is a not string!) | 283 | // push table name in fqn stack (note that concatenation will crash if name is a not string!) |
284 | lua_pushvalue(L_, -2); // L_: ... {i_} {bfc} k {} k | 284 | lua_pushvalue(L_, -2); // L_: ... {i_} {bfc} k {} k |
285 | lua_rawseti(L_, fqn, depth_); // L_: ... {i_} {bfc} k {} | 285 | lua_rawseti(L_, _fqn, depth_); // L_: ... {i_} {bfc} k {} |
286 | populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(U_) L_, dbIdx_, lua_gettop(L_), depth_); | 286 | populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(U_) L_, dbIdx_, lua_gettop(L_), depth_); |
287 | lua_pop(L_, 1); // L_: ... {i_} {bfc} k | 287 | lua_pop(L_, 1); // L_: ... {i_} {bfc} k |
288 | STACK_CHECK(L_, 2); | 288 | STACK_CHECK(L_, 2); |
289 | } | 289 | } |
290 | // remove table name from fqn stack | 290 | // remove table name from fqn stack |
291 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil | 291 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil |
292 | lua_rawseti(L_, fqn, depth_); // L_: ... {i_} {bfc} | 292 | lua_rawseti(L_, _fqn, depth_); // L_: ... {i_} {bfc} |
293 | --depth_; | 293 | --depth_; |
294 | // we are done with our cache | 294 | // we are done with our cache |
295 | lua_pop(L_, 1); // L_: ... {i_} | 295 | lua_pop(L_, 1); // L_: ... {i_} |
@@ -302,46 +302,46 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) | |||
302 | // create a "fully.qualified.name" <-> function equivalence database | 302 | // create a "fully.qualified.name" <-> function equivalence database |
303 | void populate_func_lookup_table(lua_State* L_, int i_, char const* name_) | 303 | void populate_func_lookup_table(lua_State* L_, int i_, char const* name_) |
304 | { | 304 | { |
305 | int const in_base = lua_absindex(L_, i_); | 305 | int const _in_base = lua_absindex(L_, i_); |
306 | DEBUGSPEW_CODE(Universe* U = universe_get(L_)); | 306 | DEBUGSPEW_CODE(Universe* _U = universe_get(L_)); |
307 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%p: populate_func_lookup_table('%s')\n" INDENT_END(U), L_, name_ ? name_ : "nullptr")); | 307 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%p: populate_func_lookup_table('%s')\n" INDENT_END(_U), L_, name_ ? name_ : "nullptr")); |
308 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); | 308 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
309 | STACK_GROW(L_, 3); | 309 | STACK_GROW(L_, 3); |
310 | STACK_CHECK_START_REL(L_, 0); | 310 | STACK_CHECK_START_REL(L_, 0); |
311 | kLookupRegKey.pushValue(L_); // L_: {} | 311 | kLookupRegKey.pushValue(L_); // L_: {} |
312 | int const dbIdx{ lua_gettop(L_) }; | 312 | int const _dbIdx{ lua_gettop(L_) }; |
313 | STACK_CHECK(L_, 1); | 313 | STACK_CHECK(L_, 1); |
314 | LUA_ASSERT(L_, lua_istable(L_, -1)); | 314 | LUA_ASSERT(L_, lua_istable(L_, -1)); |
315 | if (lua_type(L_, in_base) == LUA_TFUNCTION) { // for example when a module is a simple function | 315 | if (lua_type(L_, _in_base) == LUA_TFUNCTION) { // for example when a module is a simple function |
316 | name_ = name_ ? name_ : "nullptr"; | 316 | name_ = name_ ? name_ : "nullptr"; |
317 | lua_pushvalue(L_, in_base); // L_: {} f | 317 | lua_pushvalue(L_, _in_base); // L_: {} f |
318 | lua_pushstring(L_, name_); // L_: {} f _name | 318 | lua_pushstring(L_, name_); // L_: {} f _name |
319 | lua_rawset(L_, -3); // L_: {} | 319 | lua_rawset(L_, -3); // L_: {} |
320 | lua_pushstring(L_, name_); // L_: {} _name | 320 | lua_pushstring(L_, name_); // L_: {} _name |
321 | lua_pushvalue(L_, in_base); // L_: {} _name f | 321 | lua_pushvalue(L_, _in_base); // L_: {} _name f |
322 | lua_rawset(L_, -3); // L_: {} | 322 | lua_rawset(L_, -3); // L_: {} |
323 | lua_pop(L_, 1); // L_: | 323 | lua_pop(L_, 1); // L_: |
324 | } else if (lua_type(L_, in_base) == LUA_TTABLE) { | 324 | } else if (lua_type(L_, _in_base) == LUA_TTABLE) { |
325 | lua_newtable(L_); // L_: {} {fqn} | 325 | lua_newtable(L_); // L_: {} {fqn} |
326 | int startDepth{ 0 }; | 326 | int _startDepth{ 0 }; |
327 | if (name_) { | 327 | if (name_) { |
328 | STACK_CHECK(L_, 2); | 328 | STACK_CHECK(L_, 2); |
329 | lua_pushstring(L_, name_); // L_: {} {fqn} "name" | 329 | lua_pushstring(L_, name_); // L_: {} {fqn} "name" |
330 | // generate a name, and if we already had one name, keep whichever is the shorter | 330 | // generate a name, and if we already had one name, keep whichever is the shorter |
331 | lua_pushvalue(L_, in_base); // L_: {} {fqn} "name" t | 331 | lua_pushvalue(L_, _in_base); // L_: {} {fqn} "name" t |
332 | update_lookup_entry(DEBUGSPEW_PARAM_COMMA(U) L_, dbIdx, startDepth); // L_: {} {fqn} "name" | 332 | update_lookup_entry(DEBUGSPEW_PARAM_COMMA(_U) L_, _dbIdx, _startDepth); // L_: {} {fqn} "name" |
333 | // don't forget to store the name at the bottom of the fqn stack | 333 | // don't forget to store the name at the bottom of the fqn stack |
334 | lua_rawseti(L_, -2, ++startDepth); // L_: {} {fqn} | 334 | lua_rawseti(L_, -2, ++_startDepth); // L_: {} {fqn} |
335 | STACK_CHECK(L_, 2); | 335 | STACK_CHECK(L_, 2); |
336 | } | 336 | } |
337 | // retrieve the cache, create it if we haven't done it yet | 337 | // retrieve the cache, create it if we haven't done it yet |
338 | std::ignore = kLookupCacheRegKey.getSubTable(L_, 0, 0); // L_: {} {fqn} {cache} | 338 | std::ignore = kLookupCacheRegKey.getSubTable(L_, 0, 0); // L_: {} {fqn} {cache} |
339 | // process everything we find in that table, filling in lookup data for all functions and tables we see there | 339 | // process everything we find in that table, filling in lookup data for all functions and tables we see there |
340 | populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(U) L_, dbIdx, in_base, startDepth); | 340 | populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(_U) L_, _dbIdx, _in_base, _startDepth); |
341 | lua_pop(L_, 3); // L_: | 341 | lua_pop(L_, 3); // L_: |
342 | } else { | 342 | } else { |
343 | lua_pop(L_, 1); // L_: | 343 | lua_pop(L_, 1); // L_: |
344 | raise_luaL_error(L_, "unsupported module type %s", lua_typename(L_, lua_type(L_, in_base))); | 344 | raise_luaL_error(L_, "unsupported module type %s", lua_typename(L_, lua_type(L_, _in_base))); |
345 | } | 345 | } |
346 | STACK_CHECK(L_, 0); | 346 | STACK_CHECK(L_, 0); |
347 | } | 347 | } |
@@ -484,9 +484,9 @@ void populate_func_lookup_table(lua_State* L_, int i_, char const* name_) | |||
484 | // "type", "name" = lanes.nameof(o) | 484 | // "type", "name" = lanes.nameof(o) |
485 | int luaG_nameof(lua_State* L_) | 485 | int luaG_nameof(lua_State* L_) |
486 | { | 486 | { |
487 | int const what{ lua_gettop(L_) }; | 487 | int const _what{ lua_gettop(L_) }; |
488 | if (what > 1) { | 488 | if (_what > 1) { |
489 | raise_luaL_argerror(L_, what, "too many arguments."); | 489 | raise_luaL_argerror(L_, _what, "too many arguments."); |
490 | } | 490 | } |
491 | 491 | ||
492 | // nil, boolean, light userdata, number and string aren't identifiable | 492 | // nil, boolean, light userdata, number and string aren't identifiable |