| 46 | namespace stack_detail { |
| 47 | template <typename T> |
| 48 | inline bool integer_value_fits(const T& value) { |
| 49 | // We check if we can rely on casts or a lack of padding bits to satisfy |
| 50 | // the requirements here |
| 51 | // If it lacks padding bits, we can jump back and forth between lua_Integer and whatever type without |
| 52 | // loss of information |
| 53 | constexpr bool is_same_signedness |
| 54 | = (std::is_signed_v<T> && std::is_signed_v<lua_Integer>) || (std::is_unsigned_v<T> && std::is_unsigned_v<lua_Integer>); |
| 55 | constexpr bool probaby_fits_within_lua_Integer = sizeof(T) == sizeof(lua_Integer) |
| 56 | #if SOL_IS_ON(SOL_ALL_INTEGER_VALUES_FIT) |
| 57 | && ((std::has_unique_object_representations_v<T> && std::has_unique_object_representations_v<lua_Integer>) ? true : is_same_signedness) |
| 58 | #else |
| 59 | && is_same_signedness |
| 60 | #endif |
| 61 | ; |
| 62 | if constexpr (sizeof(T) < sizeof(lua_Integer) || probaby_fits_within_lua_Integer) { |
| 63 | (void)value; |
| 64 | return true; |
| 65 | } |
| 66 | else { |
| 67 | auto u_min = static_cast<std::intmax_t>((std::numeric_limits<lua_Integer>::min)()); |
| 68 | auto u_max = static_cast<std::uintmax_t>((std::numeric_limits<lua_Integer>::max)()); |
| 69 | auto t_min = static_cast<std::intmax_t>((std::numeric_limits<T>::min)()); |
| 70 | auto t_max = static_cast<std::uintmax_t>((std::numeric_limits<T>::max)()); |
| 71 | return (u_min <= t_min || value >= static_cast<T>(u_min)) && (u_max >= t_max || value <= static_cast<T>(u_max)); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | template <typename T> |
| 76 | int msvc_is_ass_with_if_constexpr_push_enum(std::true_type, lua_State* L, const T& value) { |
nothing calls this directly
no outgoing calls
no test coverage detected