aboutsummaryrefslogtreecommitdiff
path: root/src/nameof.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/nameof.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/nameof.cpp b/src/nameof.cpp
index 3c82603..fd31a28 100644
--- a/src/nameof.cpp
+++ b/src/nameof.cpp
@@ -34,10 +34,10 @@ THE SOFTWARE.
34// Return some name helping to identify an object 34// Return some name helping to identify an object
35[[nodiscard]] static int DiscoverObjectNameRecur(lua_State* L_, int shortest_, int depth_) 35[[nodiscard]] static int DiscoverObjectNameRecur(lua_State* L_, int shortest_, int depth_)
36{ 36{
37 static constexpr int kWhat{ 1 }; // the object to investigate // L_: o "r" {c} {fqn} ... {?} 37 static constexpr StackIndex kWhat{ 1 }; // the object to investigate // L_: o "r" {c} {fqn} ... {?}
38 static constexpr int kResult{ 2 }; // where the result string is stored 38 static constexpr StackIndex kResult{ 2 }; // where the result string is stored
39 static constexpr int kCache{ 3 }; // a cache 39 static constexpr StackIndex kCache{ 3 }; // a cache
40 static constexpr int kFQN{ 4 }; // the name compositing stack 40 static constexpr StackIndex kFQN{ 4 }; // the name compositing stack
41 // no need to scan this table if the name we will discover is longer than one we already know 41 // no need to scan this table if the name we will discover is longer than one we already know
42 if (shortest_ <= depth_ + 1) { 42 if (shortest_ <= depth_ + 1) {
43 return shortest_; 43 return shortest_;
@@ -80,7 +80,7 @@ THE SOFTWARE.
80 STACK_CHECK(L_, 0); 80 STACK_CHECK(L_, 0);
81 break; 81 break;
82 } 82 }
83 switch (luaG_type(L_, -1)) { // L_: o "r" {c} {fqn} ... {?} k v 83 switch (luaG_type(L_, kIdxTop)) { // L_: o "r" {c} {fqn} ... {?} k v
84 default: // nil, boolean, light userdata, number and string aren't identifiable 84 default: // nil, boolean, light userdata, number and string aren't identifiable
85 break; 85 break;
86 86
@@ -126,7 +126,7 @@ THE SOFTWARE.
126 // search in the object's uservalues 126 // search in the object's uservalues
127 { 127 {
128 int _uvi{ 1 }; 128 int _uvi{ 1 };
129 while (lua_getiuservalue(L_, -1, _uvi) != LUA_TNONE) { // L_: o "r" {c} {fqn} ... {?} k U {u} 129 while (lua_getiuservalue(L_, kIdxTop, _uvi) != LUA_TNONE) { // L_: o "r" {c} {fqn} ... {?} k U {u}
130 if (lua_istable(L_, -1)) { // if it is a table, look inside 130 if (lua_istable(L_, -1)) { // if it is a table, look inside
131 ++depth_; 131 ++depth_;
132 luaG_pushstring(L_, "uservalue"); // L_: o "r" {c} {fqn} ... {?} k v {u} "uservalue" 132 luaG_pushstring(L_, "uservalue"); // L_: o "r" {c} {fqn} ... {?} k v {u} "uservalue"
@@ -167,13 +167,13 @@ THE SOFTWARE.
167// "type", "name" = lanes.nameof(o) 167// "type", "name" = lanes.nameof(o)
168LUAG_FUNC(nameof) 168LUAG_FUNC(nameof)
169{ 169{
170 int const _what{ lua_gettop(L_) }; 170 StackIndex const _what{ lua_gettop(L_) };
171 if (_what > 1) { 171 if (_what > 1) {
172 raise_luaL_argerror(L_, _what, "too many arguments."); 172 raise_luaL_argerror(L_, _what, "too many arguments.");
173 } 173 }
174 174
175 // nil, boolean, light userdata, number and string aren't identifiable 175 // nil, boolean, light userdata, number and string aren't identifiable
176 if (luaG_type(L_, 1) < LuaType::TABLE) { 176 if (luaG_type(L_, StackIndex{ 1 }) < LuaType::TABLE) {
177 lua_pushstring(L_, luaL_typename(L_, 1)); // L_: o "type" 177 lua_pushstring(L_, luaL_typename(L_, 1)); // L_: o "type"
178 lua_insert(L_, -2); // L_: "type" o 178 lua_insert(L_, -2); // L_: "type" o
179 return 2; 179 return 2;
@@ -197,7 +197,7 @@ LUAG_FUNC(nameof)
197 lua_pop(L_, 1); // L_: o nil {c} {fqn} 197 lua_pop(L_, 1); // L_: o nil {c} {fqn}
198 luaG_pushstring(L_, "_R"); // L_: o nil {c} {fqn} "_R" 198 luaG_pushstring(L_, "_R"); // L_: o nil {c} {fqn} "_R"
199 lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} 199 lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn}
200 lua_pushvalue(L_, LUA_REGISTRYINDEX); // L_: o nil {c} {fqn} _R 200 lua_pushvalue(L_, kIdxRegistry); // L_: o nil {c} {fqn} _R
201 std::ignore = DiscoverObjectNameRecur(L_, std::numeric_limits<int>::max(), 1); 201 std::ignore = DiscoverObjectNameRecur(L_, std::numeric_limits<int>::max(), 1);
202 } 202 }
203 lua_pop(L_, 3); // L_: o "result" 203 lua_pop(L_, 3); // L_: o "result"