diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-19 11:18:17 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-19 11:18:17 +0200 |
| commit | fc971e91a377c58f804d34e146833c7b9cba8d33 (patch) | |
| tree | 8006cdfa1fd7c28160e0e7df41b521aa212f5537 /src | |
| parent | 1ca04d529a447341268cb92022e36abb09fe1315 (diff) | |
| download | lanes-fc971e91a377c58f804d34e146833c7b9cba8d33.tar.gz lanes-fc971e91a377c58f804d34e146833c7b9cba8d33.tar.bz2 lanes-fc971e91a377c58f804d34e146833c7b9cba8d33.zip | |
Tweak luaG_getfuncsubtype
Diffstat (limited to 'src')
| -rw-r--r-- | src/state.cpp | 2 | ||||
| -rw-r--r-- | src/tools.cpp | 27 |
2 files changed, 13 insertions, 16 deletions
diff --git a/src/state.cpp b/src/state.cpp index 0757203..9cd7343 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
| @@ -153,8 +153,6 @@ namespace state { | |||
| 153 | // ############################################################################################# | 153 | // ############################################################################################# |
| 154 | // ############################################################################################# | 154 | // ############################################################################################# |
| 155 | 155 | ||
| 156 | // ############################################################################################# | ||
| 157 | |||
| 158 | lua_State* CreateState([[maybe_unused]] Universe* const U_, lua_State* const from_, std::string_view const& hint_) | 156 | lua_State* CreateState([[maybe_unused]] Universe* const U_, lua_State* const from_, std::string_view const& hint_) |
| 159 | { | 157 | { |
| 160 | lua_State* const _L { | 158 | lua_State* const _L { |
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 }; | |||
| 48 | static constexpr int kWriterReturnCode{ 666 }; | 48 | static 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 | ||
