aboutsummaryrefslogtreecommitdiff
path: root/src/tools.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools.cpp')
-rw-r--r--src/tools.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/tools.cpp b/src/tools.cpp
index 14786b2..d580f67 100644
--- a/src/tools.cpp
+++ b/src/tools.cpp
@@ -48,6 +48,7 @@ static constexpr RegistryUniqueKey kLookupCacheRegKey{ 0x9BF75F84E54B691Bull };
48static constexpr int kWriterReturnCode{ 666 }; 48static constexpr int kWriterReturnCode{ 666 };
49[[nodiscard]] static int dummy_writer([[maybe_unused]] lua_State* L_, [[maybe_unused]] void const* p_, [[maybe_unused]] size_t sz_, [[maybe_unused]] void* ud_) 49[[nodiscard]] static int dummy_writer([[maybe_unused]] lua_State* L_, [[maybe_unused]] void const* p_, [[maybe_unused]] size_t sz_, [[maybe_unused]] void* ud_)
50{ 50{
51 // always fail with this code
51 return kWriterReturnCode; 52 return kWriterReturnCode;
52} 53}
53 54
@@ -70,21 +71,19 @@ FuncSubType luaG_getfuncsubtype(lua_State* const L_, int const i_)
70 if (lua_tocfunction(L_, i_)) { // nullptr for LuaJIT-fast && bytecode functions 71 if (lua_tocfunction(L_, i_)) { // nullptr for LuaJIT-fast && bytecode functions
71 return FuncSubType::Native; 72 return FuncSubType::Native;
72 } 73 }
73 { 74
74 int _mustpush{ 0 }; 75 // luaG_dump expects the function at the top of the stack
75 if (luaG_absindex(L_, i_) != lua_gettop(L_)) { 76 int const _popCount{ (luaG_absindex(L_, i_) == lua_gettop(L_)) ? 0 : (lua_pushvalue(L_, i_), 1) };
76 lua_pushvalue(L_, i_); 77 // here we either have a Lua bytecode or a LuaJIT-compiled function
77 _mustpush = 1; 78 int const _dumpres{ luaG_dump(L_, dummy_writer, nullptr, 0) };
78 } 79 if (_popCount > 0) {
79 // the provided writer fails with code kWriterReturnCode 80 lua_pop(L_, _popCount);
80 // therefore, anytime we get kWriterReturnCode, this means that luaG_dump() attempted a dump 81 }
81 // all other cases mean this is either a C or LuaJIT-fast function 82 if (_dumpres == kWriterReturnCode) {
82 int const _dumpres{ luaG_dump(L_, dummy_writer, nullptr, 0) }; 83 // anytime we get kWriterReturnCode, this means that luaG_dump() attempted a dump
83 lua_pop(L_, _mustpush); 84 return FuncSubType::Bytecode;
84 if (_dumpres == kWriterReturnCode) {
85 return FuncSubType::Bytecode;
86 }
87 } 85 }
86 // we didn't try to dump, therefore this is a LuaJIT-fast function
88 return FuncSubType::FastJIT; 87 return FuncSubType::FastJIT;
89} 88}
90 89