diff options
Diffstat (limited to 'src/tools.cpp')
-rw-r--r-- | src/tools.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/tools.cpp b/src/tools.cpp index eff865c..8ddce75 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -44,24 +44,24 @@ static constexpr RegistryUniqueKey kLookupCacheRegKey{ 0x9BF75F84E54B691Bull }; | |||
44 | 44 | ||
45 | // ################################################################################################# | 45 | // ################################################################################################# |
46 | 46 | ||
47 | static constexpr int kWriterReturnCode{ 666 }; | ||
47 | [[nodiscard]] static int dummy_writer([[maybe_unused]] lua_State* L_, [[maybe_unused]] void const* p_, [[maybe_unused]] size_t sz_, [[maybe_unused]] void* ud_) | 48 | [[nodiscard]] static int dummy_writer([[maybe_unused]] lua_State* L_, [[maybe_unused]] void const* p_, [[maybe_unused]] size_t sz_, [[maybe_unused]] void* ud_) |
48 | { | 49 | { |
49 | return 666; | 50 | return kWriterReturnCode; |
50 | } | 51 | } |
51 | 52 | ||
52 | /* | 53 | /* |
53 | * differentiation between C, bytecode and JIT-fast functions | 54 | * differentiation between C, bytecode and JIT-fast functions |
54 | * | 55 | * |
55 | * | 56 | * +-------------------+------------+----------+ |
56 | * +----------+------------+----------+ | 57 | * | bytecode | C function | JIT-fast | |
57 | * | bytecode | C function | JIT-fast | | 58 | * +-----------------+-------------------+------------+----------+ |
58 | * +-----------------+----------+------------+----------+ | 59 | * | lua_topointer | | | | |
59 | * | lua_topointer | | | | | 60 | * +-----------------+-------------------+------------+----------+ |
60 | * +-----------------+----------+------------+----------+ | 61 | * | lua_tocfunction | nullptr | | nullptr | |
61 | * | lua_tocfunction | nullptr | | nullptr | | 62 | * +-----------------+-------------------+------------+----------+ |
62 | * +-----------------+----------+------------+----------+ | 63 | * | lua_dump | kWriterReturnCode | 1 | 1 | |
63 | * | lua_dump | 666 | 1 | 1 | | 64 | * +-----------------+-------------------+------------+----------+ |
64 | * +-----------------+----------+------------+----------+ | ||
65 | */ | 65 | */ |
66 | 66 | ||
67 | [[nodiscard]] FuncSubType luaG_getfuncsubtype(lua_State* L_, int _i) | 67 | [[nodiscard]] FuncSubType luaG_getfuncsubtype(lua_State* L_, int _i) |
@@ -75,12 +75,12 @@ static constexpr RegistryUniqueKey kLookupCacheRegKey{ 0x9BF75F84E54B691Bull }; | |||
75 | lua_pushvalue(L_, _i); | 75 | lua_pushvalue(L_, _i); |
76 | _mustpush = 1; | 76 | _mustpush = 1; |
77 | } | 77 | } |
78 | // the provided writer fails with code 666 | 78 | // the provided writer fails with code kWriterReturnCode |
79 | // therefore, anytime we get 666, this means that lua_dump() attempted a dump | 79 | // therefore, anytime we get kWriterReturnCode, this means that lua_dump() attempted a dump |
80 | // all other cases mean this is either a C or LuaJIT-fast function | 80 | // all other cases mean this is either a C or LuaJIT-fast function |
81 | int const dumpres{ lua504_dump(L_, dummy_writer, nullptr, 0) }; | 81 | int const _dumpres{ lua504_dump(L_, dummy_writer, nullptr, 0) }; |
82 | lua_pop(L_, _mustpush); | 82 | lua_pop(L_, _mustpush); |
83 | if (dumpres == 666) { | 83 | if (_dumpres == kWriterReturnCode) { |
84 | return FuncSubType::Bytecode; | 84 | return FuncSubType::Bytecode; |
85 | } | 85 | } |
86 | } | 86 | } |
@@ -438,13 +438,13 @@ void populate_func_lookup_table(lua_State* L_, int i_, char const* name_) | |||
438 | lua_rawseti(L_, kFQN, depth_); // L_: o "r" {c} {fqn} ... {?} k U {mt} | 438 | lua_rawseti(L_, kFQN, depth_); // L_: o "r" {c} {fqn} ... {?} k U {mt} |
439 | --depth_; | 439 | --depth_; |
440 | } | 440 | } |
441 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... {?} k U | 441 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... {?} k U |
442 | } | 442 | } |
443 | STACK_CHECK(L_, 2); | 443 | STACK_CHECK(L_, 2); |
444 | // search in the object's uservalues | 444 | // search in the object's uservalues |
445 | { | 445 | { |
446 | int uvi = 1; | 446 | int _uvi{ 1 }; |
447 | while (lua_getiuservalue(L_, -1, uvi) != LUA_TNONE) { // L_: o "r" {c} {fqn} ... {?} k U {u} | 447 | while (lua_getiuservalue(L_, -1, _uvi) != LUA_TNONE) { // L_: o "r" {c} {fqn} ... {?} k U {u} |
448 | if (lua_istable(L_, -1)) { // if it is a table, look inside | 448 | if (lua_istable(L_, -1)) { // if it is a table, look inside |
449 | ++depth_; | 449 | ++depth_; |
450 | lua_pushliteral(L_, "uservalue"); // L_: o "r" {c} {fqn} ... {?} k v {u} "uservalue" | 450 | lua_pushliteral(L_, "uservalue"); // L_: o "r" {c} {fqn} ... {?} k v {u} "uservalue" |
@@ -455,7 +455,7 @@ void populate_func_lookup_table(lua_State* L_, int i_, char const* name_) | |||
455 | --depth_; | 455 | --depth_; |
456 | } | 456 | } |
457 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... {?} k U | 457 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... {?} k U |
458 | ++uvi; | 458 | ++_uvi; |
459 | } | 459 | } |
460 | // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now | 460 | // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now |
461 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... {?} k U | 461 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... {?} k U |
@@ -510,13 +510,13 @@ int luaG_nameof(lua_State* L_) | |||
510 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} | 510 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} |
511 | // this is where we start the search | 511 | // this is where we start the search |
512 | lua_pushglobaltable(L_); // L_: o nil {c} {fqn} _G | 512 | lua_pushglobaltable(L_); // L_: o nil {c} {fqn} _G |
513 | std::ignore = DiscoverObjectNameRecur(L_, 6666, 1); | 513 | std::ignore = DiscoverObjectNameRecur(L_, std::numeric_limits<int>::max(), 1); |
514 | if (lua_isnil(L_, 2)) { // try again with registry, just in case... | 514 | if (lua_isnil(L_, 2)) { // try again with registry, just in case... |
515 | lua_pop(L_, 1); // L_: o nil {c} {fqn} | 515 | lua_pop(L_, 1); // L_: o nil {c} {fqn} |
516 | lua_pushliteral(L_, "_R"); // L_: o nil {c} {fqn} "_R" | 516 | lua_pushliteral(L_, "_R"); // L_: o nil {c} {fqn} "_R" |
517 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} | 517 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} |
518 | lua_pushvalue(L_, LUA_REGISTRYINDEX); // L_: o nil {c} {fqn} _R | 518 | lua_pushvalue(L_, LUA_REGISTRYINDEX); // L_: o nil {c} {fqn} _R |
519 | std::ignore = DiscoverObjectNameRecur(L_, 6666, 1); | 519 | std::ignore = DiscoverObjectNameRecur(L_, std::numeric_limits<int>::max(), 1); |
520 | } | 520 | } |
521 | lua_pop(L_, 3); // L_: o "result" | 521 | lua_pop(L_, 3); // L_: o "result" |
522 | STACK_CHECK(L_, 1); | 522 | STACK_CHECK(L_, 1); |