c_str is not a std::string and I fucking hate it

This commit is contained in:
ThePhD 2021-10-22 19:06:43 -04:00
parent 03ec2c93cc
commit ff783a150c
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA
4 changed files with 23 additions and 11 deletions

View File

@ -28,6 +28,7 @@
#include <sol/stack.hpp> #include <sol/stack.hpp>
#include <sol/stack_reference.hpp> #include <sol/stack_reference.hpp>
#include <sol/assert.hpp>
namespace sol { namespace stack { namespace stack_detail { namespace sol { namespace stack { namespace stack_detail {

View File

@ -33,11 +33,11 @@ namespace sol { namespace stack {
namespace stack_detail { namespace stack_detail {
template <typename T, bool global, bool raw> template <typename T, bool global, bool raw>
inline constexpr bool is_get_direct_tableless_v = (global && !raw && meta::is_c_str_v<T>); inline constexpr bool is_get_direct_tableless_v = (global && !raw && meta::is_c_str_or_string_v<T>);
template <typename T, bool global, bool raw> template <typename T, bool global, bool raw>
inline constexpr bool is_get_direct_v = (is_get_direct_tableless_v<T, global, raw>) // cf-hack inline constexpr bool is_get_direct_v = (is_get_direct_tableless_v<T, global, raw>) // cf-hack
|| (!global && !raw && (meta::is_c_str_v<T> || meta::is_string_of_v<T, char>)) // cf-hack || (!global && !raw && (meta::is_c_str_or_string_v<T> || meta::is_string_of_v<T, char>)) // cf-hack
|| (!global && raw && (std::is_integral_v<T> && !std::is_same_v<T, bool>)) || (!global && raw && (std::is_integral_v<T> && !std::is_same_v<T, bool>))
#if SOL_LUA_VERSION_I_ >= 503 #if SOL_LUA_VERSION_I_ >= 503
|| (!global && !raw && (std::is_integral_v<T> && !std::is_same_v<T, bool>)) || (!global && !raw && (std::is_integral_v<T> && !std::is_same_v<T, bool>))
@ -48,11 +48,11 @@ namespace sol { namespace stack {
; ;
template <typename T, bool global, bool raw> template <typename T, bool global, bool raw>
inline constexpr bool is_set_direct_tableless_v = (global && !raw && meta::is_c_str_v<T>); inline constexpr bool is_set_direct_tableless_v = (global && !raw && meta::is_c_str_or_string_v<T>);
template <typename T, bool global, bool raw> template <typename T, bool global, bool raw>
inline constexpr bool is_set_direct_v = (is_set_direct_tableless_v<T, global, raw>) // cf-hack inline constexpr bool is_set_direct_v = (is_set_direct_tableless_v<T, global, raw>) // cf-hack
|| (!global && !raw && (meta::is_c_str_v<T> || meta::is_string_of_v<T, char>)) // cf-hack || (!global && !raw && (meta::is_c_str_or_string_v<T> || meta::is_string_of_v<T, char>)) // cf-hack
|| (!global && raw && (std::is_integral_v<T> && !std::is_same_v<T, bool>)) // cf-hack || (!global && raw && (std::is_integral_v<T> && !std::is_same_v<T, bool>)) // cf-hack
#if SOL_LUA_VERSION_I_ >= 503 #if SOL_LUA_VERSION_I_ >= 503
|| (!global && !raw && (std::is_integral_v<T> && !std::is_same_v<T, bool>)) || (!global && !raw && (std::is_integral_v<T> && !std::is_same_v<T, bool>))
@ -107,7 +107,7 @@ namespace sol { namespace stack {
} }
} }
else { else {
if constexpr (meta::is_c_str_v<T>) { if constexpr (meta::is_c_str_or_string_v<T>) {
if constexpr (global) { if constexpr (global) {
(void)tableindex; (void)tableindex;
lua_getglobal(L, &key[0]); lua_getglobal(L, &key[0]);
@ -212,7 +212,7 @@ namespace sol { namespace stack {
} }
} }
else { else {
if constexpr (meta::is_c_str_v<T> || meta::is_string_of_v<T, char>) { if constexpr (meta::is_c_str_v<T>) {
if constexpr (global) { if constexpr (global) {
push(L, std::forward<Value>(value)); push(L, std::forward<Value>(value));
lua_setglobal(L, &key[0]); lua_setglobal(L, &key[0]);

View File

@ -678,8 +678,7 @@ namespace sol { namespace meta {
struct is_pair<std::pair<T1, T2>> : std::true_type { }; struct is_pair<std::pair<T1, T2>> : std::true_type { };
template <typename T, typename Char> template <typename T, typename Char>
using is_c_str_of = any<std::is_same<T, const Char*>, std::is_same<T, Char const* const>, std::is_same<T, Char*>, is_string_of<T, Char>, using is_c_str_of = any<std::is_same<T, const Char*>, std::is_same<T, Char const* const>, std::is_same<T, Char*>, is_string_literal_array_of<T, Char>>;
is_string_literal_array_of<T, Char>>;
template <typename T, typename Char> template <typename T, typename Char>
constexpr inline bool is_c_str_of_v = is_c_str_of<T, Char>::value; constexpr inline bool is_c_str_of_v = is_c_str_of<T, Char>::value;
@ -690,6 +689,18 @@ namespace sol { namespace meta {
template <typename T> template <typename T>
constexpr inline bool is_c_str_v = is_c_str<T>::value; constexpr inline bool is_c_str_v = is_c_str<T>::value;
template <typename T, typename Char>
using is_c_str_or_string_of = any<is_c_str_of<T, Char>, is_string_of<T, Char>>;
template <typename T, typename Char>
constexpr inline bool is_c_str_or_string_of_v = is_c_str_or_string_of<T, Char>::value;
template <typename T>
using is_c_str_or_string = is_c_str_or_string_of<T, char>;
template <typename T>
constexpr inline bool is_c_str_or_string_v = is_c_str<T>::value;
template <typename T> template <typename T>
struct is_move_only : all<neg<std::is_reference<T>>, neg<std::is_copy_constructible<unqualified_t<T>>>, std::is_move_constructible<unqualified_t<T>>> { }; struct is_move_only : all<neg<std::is_reference<T>>, neg<std::is_copy_constructible<unqualified_t<T>>>, std::is_move_constructible<unqualified_t<T>>> { };

View File

@ -66,11 +66,11 @@ namespace sol { namespace u_detail {
template <typename K, typename Fq, typename T = void> template <typename K, typename Fq, typename T = void>
struct binding : binding_base { struct binding : binding_base {
using uF = meta::unqualified_t<Fq>; using uF = meta::unqualified_t<Fq>;
using F = meta::conditional_t<meta::is_c_str_of_v<uF, char> using F = meta::conditional_t<meta::is_c_str_or_string_of_v<uF, char>
#if SOL_IS_ON(SOL_CHAR8_T_I_) #if SOL_IS_ON(SOL_CHAR8_T_I_)
|| meta::is_c_str_of_v<uF, char8_t> || meta::is_c_str_or_string_of_v<uF, char8_t>
#endif #endif
|| meta::is_c_str_of_v<uF, char16_t> || meta::is_c_str_of_v<uF, char32_t> || meta::is_c_str_of_v<uF, wchar_t>, || meta::is_c_str_or_string_of_v<uF, char16_t> || meta::is_c_str_or_string_of_v<uF, char32_t> || meta::is_c_str_or_string_of_v<uF, wchar_t>,
std::add_pointer_t<std::add_const_t<std::remove_all_extents_t<Fq>>>, std::decay_t<Fq>>; std::add_pointer_t<std::add_const_t<std::remove_all_extents_t<Fq>>>, std::decay_t<Fq>>;
F data_; F data_;