diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2025-07-04 13:50:53 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2025-07-04 13:50:53 +0200 |
| commit | 042055968ab0c48faec607889814e38c50c09efa (patch) | |
| tree | 4ec067a03ffcb720d8bf38968d5f84ccec8230d0 /src/nameof.cpp | |
| parent | 963afcbb3d9dac47b84552ed11e53a0641ad924d (diff) | |
| download | lanes-042055968ab0c48faec607889814e38c50c09efa.tar.gz lanes-042055968ab0c48faec607889814e38c50c09efa.tar.bz2 lanes-042055968ab0c48faec607889814e38c50c09efa.zip | |
Changed lua wrapper prefixes from luaG_ to luaW_ (w as in wrapper!)
Diffstat (limited to 'src/nameof.cpp')
| -rw-r--r-- | src/nameof.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/nameof.cpp b/src/nameof.cpp index f236f73..992569b 100644 --- a/src/nameof.cpp +++ b/src/nameof.cpp | |||
| @@ -52,25 +52,25 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ | |||
| 52 | static constexpr auto _pushNameOnFQN = [](lua_State* const L_) { | 52 | static constexpr auto _pushNameOnFQN = [](lua_State* const L_) { |
| 53 | STACK_CHECK_START_REL(L_, 0); | 53 | STACK_CHECK_START_REL(L_, 0); |
| 54 | lua_pushvalue(L_, -2); // L_: o "r" {c} {fqn} ... k v k | 54 | lua_pushvalue(L_, -2); // L_: o "r" {c} {fqn} ... k v k |
| 55 | auto const _keyType{ luaG_type(L_, kIdxTop) }; | 55 | auto const _keyType{ luaW_type(L_, kIdxTop) }; |
| 56 | if (_keyType != LuaType::STRING) { | 56 | if (_keyType != LuaType::STRING) { |
| 57 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k v | 57 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k v |
| 58 | luaG_pushstring(L_, "<%s>", luaG_typename(L_, _keyType).data()); // L_: o "r" {c} {fqn} ... k v "<type of k>" | 58 | luaW_pushstring(L_, "<%s>", luaW_typename(L_, _keyType).data()); // L_: o "r" {c} {fqn} ... k v "<type of k>" |
| 59 | } else { | 59 | } else { |
| 60 | // decorate the key string with something that tells us the type of the value | 60 | // decorate the key string with something that tells us the type of the value |
| 61 | switch (luaG_type(L_, StackIndex{ -2 })) { | 61 | switch (luaW_type(L_, StackIndex{ -2 })) { |
| 62 | default: | 62 | default: |
| 63 | LUA_ASSERT(L_, false); // there is something wrong if we end up here | 63 | LUA_ASSERT(L_, false); // there is something wrong if we end up here |
| 64 | luaG_pushstring(L_, "??"); // L_: o "r" {c} {fqn} ... k v "k" "??" | 64 | luaW_pushstring(L_, "??"); // L_: o "r" {c} {fqn} ... k v "k" "??" |
| 65 | break; | 65 | break; |
| 66 | case LuaType::FUNCTION: | 66 | case LuaType::FUNCTION: |
| 67 | luaG_pushstring(L_, "()"); // L_: o "r" {c} {fqn} ... k v "k" "()" | 67 | luaW_pushstring(L_, "()"); // L_: o "r" {c} {fqn} ... k v "k" "()" |
| 68 | break; | 68 | break; |
| 69 | case LuaType::TABLE: | 69 | case LuaType::TABLE: |
| 70 | luaG_pushstring(L_, "[]"); // L_: o "r" {c} {fqn} ... k v "k" "[]" | 70 | luaW_pushstring(L_, "[]"); // L_: o "r" {c} {fqn} ... k v "k" "[]" |
| 71 | break; | 71 | break; |
| 72 | case LuaType::USERDATA: | 72 | case LuaType::USERDATA: |
| 73 | luaG_pushstring(L_, "<>"); // L_: o "r" {c} {fqn} ... k v "k" "<>" | 73 | luaW_pushstring(L_, "<>"); // L_: o "r" {c} {fqn} ... k v "k" "<>" |
| 74 | break; | 74 | break; |
| 75 | } | 75 | } |
| 76 | lua_concat(L_, 2); // L_: o "r" {c} {fqn} ... k v "k??" | 76 | lua_concat(L_, 2); // L_: o "r" {c} {fqn} ... k v "k??" |
| @@ -92,7 +92,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ | |||
| 92 | static constexpr auto _recurseThenPop = [](lua_State* const L_, FqnLength const shortest_) -> FqnLength { | 92 | static constexpr auto _recurseThenPop = [](lua_State* const L_, FqnLength const shortest_) -> FqnLength { |
| 93 | STACK_CHECK_START_REL(L_, 0); // L_: o "r" {c} {fqn} ... <> | 93 | STACK_CHECK_START_REL(L_, 0); // L_: o "r" {c} {fqn} ... <> |
| 94 | FqnLength r_{ shortest_ }; | 94 | FqnLength r_{ shortest_ }; |
| 95 | auto const _type{ luaG_type(L_, kIdxTop) }; | 95 | auto const _type{ luaW_type(L_, kIdxTop) }; |
| 96 | if (_type == LuaType::TABLE || _type == LuaType::USERDATA || _type == LuaType::FUNCTION) { | 96 | if (_type == LuaType::TABLE || _type == LuaType::USERDATA || _type == LuaType::FUNCTION) { |
| 97 | r_ = DiscoverObjectNameRecur(L_, shortest_); | 97 | r_ = DiscoverObjectNameRecur(L_, shortest_); |
| 98 | STACK_CHECK(L_, 0); | 98 | STACK_CHECK(L_, 0); |
| @@ -113,7 +113,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ | |||
| 113 | STACK_CHECK_START_REL(L_, 0); // L_: o "r" {c} {fqn} ... k v | 113 | STACK_CHECK_START_REL(L_, 0); // L_: o "r" {c} {fqn} ... k v |
| 114 | 114 | ||
| 115 | // filter out uninteresting values | 115 | // filter out uninteresting values |
| 116 | auto const _valType{ luaG_type(L_, kIdxTop) }; | 116 | auto const _valType{ luaW_type(L_, kIdxTop) }; |
| 117 | if (_valType == LuaType::NIL || _valType == LuaType::BOOLEAN || _valType == LuaType::LIGHTUSERDATA || _valType == LuaType::NUMBER || _valType == LuaType::STRING) { | 117 | if (_valType == LuaType::NIL || _valType == LuaType::BOOLEAN || _valType == LuaType::LIGHTUSERDATA || _valType == LuaType::NUMBER || _valType == LuaType::STRING) { |
| 118 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k | 118 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k |
| 119 | return _r; | 119 | return _r; |
| @@ -177,7 +177,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ | |||
| 177 | 177 | ||
| 178 | UserValueIndex _uvi{ 0 }; | 178 | UserValueIndex _uvi{ 0 }; |
| 179 | while (lua_getiuservalue(L_, kIdxTop, ++_uvi) != LUA_TNONE) { // L_: o "r" {c} {fqn} ... U uv | 179 | while (lua_getiuservalue(L_, kIdxTop, ++_uvi) != LUA_TNONE) { // L_: o "r" {c} {fqn} ... U uv |
| 180 | luaG_pushstring(L_, "<uv:%d>", _uvi); // L_: o "r" {c} {fqn} ... U uv name | 180 | luaW_pushstring(L_, "<uv:%d>", _uvi); // L_: o "r" {c} {fqn} ... U uv name |
| 181 | lua_insert(L_, -2); // L_: o "r" {c} {fqn} ... U name uv | 181 | lua_insert(L_, -2); // L_: o "r" {c} {fqn} ... U name uv |
| 182 | r_ = _processKeyValue(L_, r_); // L_: o "r" {c} {fqn} ... U name | 182 | r_ = _processKeyValue(L_, r_); // L_: o "r" {c} {fqn} ... U name |
| 183 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... U | 183 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... U |
| @@ -200,7 +200,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ | |||
| 200 | _upname = "<C>"; | 200 | _upname = "<C>"; |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | luaG_pushstring(L_, "upvalue:%s", _upname); // L_: o "r" {c} {fqn} ... F up name | 203 | luaW_pushstring(L_, "upvalue:%s", _upname); // L_: o "r" {c} {fqn} ... F up name |
| 204 | lua_insert(L_, -2); // L_: o "r" {c} {fqn} ... F name up | 204 | lua_insert(L_, -2); // L_: o "r" {c} {fqn} ... F name up |
| 205 | r_ = _processKeyValue(L_, r_); // L_: o "r" {c} {fqn} ... F name | 205 | r_ = _processKeyValue(L_, r_); // L_: o "r" {c} {fqn} ... F name |
| 206 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... F | 206 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... F |
| @@ -213,7 +213,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ | |||
| 213 | STACK_GROW(L_, 2); | 213 | STACK_GROW(L_, 2); |
| 214 | STACK_CHECK_START_REL(L_, 0); | 214 | STACK_CHECK_START_REL(L_, 0); |
| 215 | // stack top contains the location to search in (table, function, userdata) | 215 | // stack top contains the location to search in (table, function, userdata) |
| 216 | [[maybe_unused]] auto const _typeWhere{ luaG_type(L_, kIdxTop) }; | 216 | [[maybe_unused]] auto const _typeWhere{ luaW_type(L_, kIdxTop) }; |
| 217 | LUA_ASSERT(L_, _typeWhere == LuaType::TABLE || _typeWhere == LuaType::USERDATA || _typeWhere == LuaType::FUNCTION); | 217 | LUA_ASSERT(L_, _typeWhere == LuaType::TABLE || _typeWhere == LuaType::USERDATA || _typeWhere == LuaType::FUNCTION); |
| 218 | lua_pushvalue(L_, kIdxTop); // L_: o "r" {c} {fqn} ... <> <> | 218 | lua_pushvalue(L_, kIdxTop); // L_: o "r" {c} {fqn} ... <> <> |
| 219 | lua_rawget(L_, kCache); // L_: o "r" {c} {fqn} ... <> nil/N | 219 | lua_rawget(L_, kCache); // L_: o "r" {c} {fqn} ... <> nil/N |
| @@ -263,12 +263,12 @@ LUAG_FUNC(nameof) | |||
| 263 | 263 | ||
| 264 | // nil, boolean, light userdata, number and string aren't identifiable | 264 | // nil, boolean, light userdata, number and string aren't identifiable |
| 265 | static constexpr auto _isIdentifiable = [](lua_State* const L_) { | 265 | static constexpr auto _isIdentifiable = [](lua_State* const L_) { |
| 266 | auto const _valType{ luaG_type(L_, kIdxTop) }; | 266 | auto const _valType{ luaW_type(L_, kIdxTop) }; |
| 267 | return _valType == LuaType::TABLE || _valType == LuaType::FUNCTION || _valType == LuaType::USERDATA || _valType == LuaType::THREAD; | 267 | return _valType == LuaType::TABLE || _valType == LuaType::FUNCTION || _valType == LuaType::USERDATA || _valType == LuaType::THREAD; |
| 268 | }; | 268 | }; |
| 269 | 269 | ||
| 270 | if (!_isIdentifiable(L_)) { | 270 | if (!_isIdentifiable(L_)) { |
| 271 | luaG_pushstring(L_, luaG_typename(L_, kIdxTop)); // L_: o "type" | 271 | luaW_pushstring(L_, luaW_typename(L_, kIdxTop)); // L_: o "type" |
| 272 | lua_insert(L_, -2); // L_: "type" o | 272 | lua_insert(L_, -2); // L_: "type" o |
| 273 | return 2; | 273 | return 2; |
| 274 | } | 274 | } |
| @@ -282,15 +282,15 @@ LUAG_FUNC(nameof) | |||
| 282 | // push a table whose contents are strings that, when concatenated, produce unique name | 282 | // push a table whose contents are strings that, when concatenated, produce unique name |
| 283 | lua_newtable(L_); // L_: o nil {c} {fqn} | 283 | lua_newtable(L_); // L_: o nil {c} {fqn} |
| 284 | // {fqn}[1] = "_G" | 284 | // {fqn}[1] = "_G" |
| 285 | luaG_pushstring(L_, LUA_GNAME); // L_: o nil {c} {fqn} "_G" | 285 | luaW_pushstring(L_, LUA_GNAME); // L_: o nil {c} {fqn} "_G" |
| 286 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} | 286 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} |
| 287 | // this is where we start the search | 287 | // this is where we start the search |
| 288 | luaG_pushglobaltable(L_); // L_: o nil {c} {fqn} _G | 288 | luaW_pushglobaltable(L_); // L_: o nil {c} {fqn} _G |
| 289 | auto const _foundInG{ DiscoverObjectNameRecur(L_, FqnLength{ std::numeric_limits<FqnLength::type>::max() }) }; | 289 | auto const _foundInG{ DiscoverObjectNameRecur(L_, FqnLength{ std::numeric_limits<FqnLength::type>::max() }) }; |
| 290 | if (lua_isnil(L_, 2)) { // try again with registry, just in case... | 290 | if (lua_isnil(L_, 2)) { // try again with registry, just in case... |
| 291 | LUA_ASSERT(L_, _foundInG == std::numeric_limits<FqnLength::type>::max()); | 291 | LUA_ASSERT(L_, _foundInG == std::numeric_limits<FqnLength::type>::max()); |
| 292 | lua_pop(L_, 1); // L_: o nil {c} {fqn} | 292 | lua_pop(L_, 1); // L_: o nil {c} {fqn} |
| 293 | luaG_pushstring(L_, "_R"); // L_: o nil {c} {fqn} "_R" | 293 | luaW_pushstring(L_, "_R"); // L_: o nil {c} {fqn} "_R" |
| 294 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} | 294 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} |
| 295 | lua_pushvalue(L_, kIdxRegistry); // L_: o nil {c} {fqn} _R | 295 | lua_pushvalue(L_, kIdxRegistry); // L_: o nil {c} {fqn} _R |
| 296 | [[maybe_unused]] auto const _foundInR{ DiscoverObjectNameRecur(L_, FqnLength{ std::numeric_limits<FqnLength::type>::max() }) }; | 296 | [[maybe_unused]] auto const _foundInR{ DiscoverObjectNameRecur(L_, FqnLength{ std::numeric_limits<FqnLength::type>::max() }) }; |
