diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-10 09:48:59 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-10 09:48:59 +0200 |
| commit | 408f8a5bf7934e7a5aa113fd3a55899db70dd73a (patch) | |
| tree | af1a63c4d5c81fe8b2f97ee32842fe89d2c457fe /src/tools.cpp | |
| parent | 8f75e0ff26645ced3669f600aa5e9133bb7b49af (diff) | |
| download | lanes-408f8a5bf7934e7a5aa113fd3a55899db70dd73a.tar.gz lanes-408f8a5bf7934e7a5aa113fd3a55899db70dd73a.tar.bz2 lanes-408f8a5bf7934e7a5aa113fd3a55899db70dd73a.zip | |
C++ migration: luaG_inter_copy_* now return an enum class instead of an anonymous int
Diffstat (limited to 'src/tools.cpp')
| -rw-r--r-- | src/tools.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/tools.cpp b/src/tools.cpp index 9207df6..aa95f04 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
| @@ -1415,7 +1415,7 @@ static void copy_cached_func(Universe* U, Dest L2, int L2_cache_i, Source L, int | |||
| 1415 | lua_pop(L2, 1); // _R[REG_MTID] | 1415 | lua_pop(L2, 1); // _R[REG_MTID] |
| 1416 | if (!inter_copy_one(U, L2, L2_cache_i, L, lua_gettop(L), VT::METATABLE, mode_, upName_)) // _R[REG_MTID] mt? | 1416 | if (!inter_copy_one(U, L2, L2_cache_i, L, lua_gettop(L), VT::METATABLE, mode_, upName_)) // _R[REG_MTID] mt? |
| 1417 | { | 1417 | { |
| 1418 | std::ignore = luaL_error(L, "Error copying a metatable"); // doesn't return | 1418 | luaL_error(L, "Error copying a metatable"); // doesn't return |
| 1419 | } | 1419 | } |
| 1420 | 1420 | ||
| 1421 | STACK_CHECK(L2, 2); // _R[REG_MTID] mt | 1421 | STACK_CHECK(L2, 2); // _R[REG_MTID] mt |
| @@ -1600,7 +1600,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
| 1600 | { | 1600 | { |
| 1601 | if (!inter_copy_one(U, L2, L2_cache_i, L, lua_absindex(L, -1), VT::NORMAL, mode_, upName_)) // ... u uv | 1601 | if (!inter_copy_one(U, L2, L2_cache_i, L, lua_absindex(L, -1), VT::NORMAL, mode_, upName_)) // ... u uv |
| 1602 | { | 1602 | { |
| 1603 | std::ignore = luaL_error(L, "Cannot copy upvalue type '%s'", luaL_typename(L, -1)); // doesn't return | 1603 | luaL_error(L, "Cannot copy upvalue type '%s'", luaL_typename(L, -1)); // doesn't return |
| 1604 | } | 1604 | } |
| 1605 | lua_pop( L, 1); // ... mt __lanesclone [uv]* | 1605 | lua_pop( L, 1); // ... mt __lanesclone [uv]* |
| 1606 | // this pops the value from the stack | 1606 | // this pops the value from the stack |
| @@ -1670,7 +1670,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
| 1670 | } | 1670 | } |
| 1671 | else // raise an error | 1671 | else // raise an error |
| 1672 | { | 1672 | { |
| 1673 | std::ignore = luaL_error(L, "can't copy non-deep full userdata across lanes"); // doesn't return | 1673 | luaL_error(L, "can't copy non-deep full userdata across lanes"); // doesn't return |
| 1674 | } | 1674 | } |
| 1675 | 1675 | ||
| 1676 | STACK_CHECK(L2, 1); | 1676 | STACK_CHECK(L2, 1); |
| @@ -1739,7 +1739,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
| 1739 | { | 1739 | { |
| 1740 | if (!inter_copy_one(U, L2, L2_cache_i, L, lua_absindex(L, -1), vt_, mode_, upName_)) // ... mt u uv | 1740 | if (!inter_copy_one(U, L2, L2_cache_i, L, lua_absindex(L, -1), vt_, mode_, upName_)) // ... mt u uv |
| 1741 | { | 1741 | { |
| 1742 | std::ignore = luaL_error(L, "Cannot copy upvalue type '%s'", luaL_typename(L, -1)); // doesn't return | 1742 | luaL_error(L, "Cannot copy upvalue type '%s'", luaL_typename(L, -1)); // doesn't return |
| 1743 | } | 1743 | } |
| 1744 | lua_pop(L, 1); // ... u [uv]* | 1744 | lua_pop(L, 1); // ... u [uv]* |
| 1745 | // this pops the value from the stack | 1745 | // this pops the value from the stack |
| @@ -1973,7 +1973,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
| 1973 | * | 1973 | * |
| 1974 | * Note: Parameters are in this order ('L' = from first) to be same as 'lua_xmove'. | 1974 | * Note: Parameters are in this order ('L' = from first) to be same as 'lua_xmove'. |
| 1975 | */ | 1975 | */ |
| 1976 | [[nodiscard]] int luaG_inter_copy(Universe* U, Source L, Dest L2, int n, LookupMode mode_) | 1976 | [[nodiscard]] InterCopyResult luaG_inter_copy(Universe* U, Source L, Dest L2, int n, LookupMode mode_) |
| 1977 | { | 1977 | { |
| 1978 | int const top_L{ lua_gettop(L) }; // ... {}n | 1978 | int const top_L{ lua_gettop(L) }; // ... {}n |
| 1979 | int const top_L2{ lua_gettop(L2) }; // ... | 1979 | int const top_L2{ lua_gettop(L2) }; // ... |
| @@ -1988,7 +1988,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
| 1988 | // requesting to copy more than is available? | 1988 | // requesting to copy more than is available? |
| 1989 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "nothing to copy()\n" INDENT_END)); | 1989 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "nothing to copy()\n" INDENT_END)); |
| 1990 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); | 1990 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); |
| 1991 | return -1; | 1991 | return InterCopyResult::NotEnoughValues; |
| 1992 | } | 1992 | } |
| 1993 | 1993 | ||
| 1994 | STACK_CHECK_START_REL(L2, 0); | 1994 | STACK_CHECK_START_REL(L2, 0); |
| @@ -2025,25 +2025,31 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
| 2025 | // Remove the cache table. Persistent caching would cause i.e. multiple | 2025 | // Remove the cache table. Persistent caching would cause i.e. multiple |
| 2026 | // messages passed in the same table to use the same table also in receiving end. | 2026 | // messages passed in the same table to use the same table also in receiving end. |
| 2027 | lua_remove(L2, top_L2 + 1); | 2027 | lua_remove(L2, top_L2 + 1); |
| 2028 | return 0; | 2028 | return InterCopyResult::Success; |
| 2029 | } | 2029 | } |
| 2030 | 2030 | ||
| 2031 | // error -> pop everything from the target state stack | 2031 | // error -> pop everything from the target state stack |
| 2032 | lua_settop(L2, top_L2); | 2032 | lua_settop(L2, top_L2); |
| 2033 | STACK_CHECK(L2, 0); | 2033 | STACK_CHECK(L2, 0); |
| 2034 | return -2; | 2034 | return InterCopyResult::Error; |
| 2035 | } | 2035 | } |
| 2036 | 2036 | ||
| 2037 | // ################################################################################################# | 2037 | // ################################################################################################# |
| 2038 | 2038 | ||
| 2039 | [[nodiscard]] int luaG_inter_move(Universe* U, Source L, Dest L2, int n, LookupMode mode_) | 2039 | [[nodiscard]] InterCopyResult luaG_inter_move(Universe* U, Source L, Dest L2, int n_, LookupMode mode_) |
| 2040 | { | 2040 | { |
| 2041 | int const ret{ luaG_inter_copy(U, L, L2, n, mode_) }; | 2041 | InterCopyResult const ret{ luaG_inter_copy(U, L, L2, n_, mode_) }; |
| 2042 | lua_pop( L, n); | 2042 | lua_pop( L, n_); |
| 2043 | return ret; | 2043 | return ret; |
| 2044 | } | 2044 | } |
| 2045 | 2045 | ||
| 2046 | [[nodiscard]] int luaG_inter_copy_package(Universe* U, Source L, Dest L2, int package_idx_, LookupMode mode_) | 2046 | // ################################################################################################# |
| 2047 | |||
| 2048 | // transfers stuff from L->_G["package"] to L2->_G["package"] | ||
| 2049 | // returns InterCopyResult::Success if everything is fine | ||
| 2050 | // returns InterCopyResult::Error if pushed an error message in L | ||
| 2051 | // else raise an error in L | ||
| 2052 | [[nodiscard]] InterCopyResult luaG_inter_copy_package(Universe* U, Source L, Dest L2, int package_idx_, LookupMode mode_) | ||
| 2047 | { | 2053 | { |
| 2048 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "luaG_inter_copy_package()\n" INDENT_END)); | 2054 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "luaG_inter_copy_package()\n" INDENT_END)); |
| 2049 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); | 2055 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); |
| @@ -2056,7 +2062,11 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
| 2056 | lua_pushfstring(L, "expected package as table, got %s", luaL_typename(L, package_idx_)); | 2062 | lua_pushfstring(L, "expected package as table, got %s", luaL_typename(L, package_idx_)); |
| 2057 | STACK_CHECK(L, 1); | 2063 | STACK_CHECK(L, 1); |
| 2058 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later | 2064 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later |
| 2059 | return (mode_ == LookupMode::LaneBody) ? lua_error(L) : 1; | 2065 | if (mode_ == LookupMode::LaneBody) |
| 2066 | { | ||
| 2067 | lua_error(L); // doesn't return | ||
| 2068 | } | ||
| 2069 | return InterCopyResult::Error; | ||
| 2060 | } | 2070 | } |
| 2061 | lua_getglobal(L2, "package"); | 2071 | lua_getglobal(L2, "package"); |
| 2062 | if (!lua_isnil(L2, -1)) // package library not loaded: do nothing | 2072 | if (!lua_isnil(L2, -1)) // package library not loaded: do nothing |
| @@ -2095,5 +2105,5 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
| 2095 | STACK_CHECK(L2, 0); | 2105 | STACK_CHECK(L2, 0); |
| 2096 | STACK_CHECK(L, 0); | 2106 | STACK_CHECK(L, 0); |
| 2097 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); | 2107 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); |
| 2098 | return 0; | 2108 | return InterCopyResult::Success; |
| 2099 | } | 2109 | } |
