clean up interactions with unique types that are not base/derived aliasing

This commit is contained in:
ThePhD 2018-06-17 16:29:19 -04:00
parent 96143d8d79
commit 8b52c35249
4 changed files with 9 additions and 7 deletions

View File

@ -116,6 +116,7 @@ namespace sol {
static int type_unique_cast(void* source_data, void* target_data, const string_view& ti, const string_view& rebind_ti) {
typedef unique_usertype_traits<U> uu_traits;
typedef typename uu_traits::template rebind_base<void> rebind_t;
typedef std::conditional_t<std::is_void<rebind_t>::value, types<>, bases_t> cond_bases_t;
string_view this_rebind_ti = usertype_traits<rebind_t>::qualified_name();
if (rebind_ti != this_rebind_ti) {
// this is not even of the same unique type
@ -123,10 +124,10 @@ namespace sol {
}
string_view this_ti = usertype_traits<T>::qualified_name();
if (ti == this_ti) {
//
// direct match, return 1
return 1;
}
return type_unique_cast_bases<U>(bases_t(), source_data, target_data, ti);
return type_unique_cast_bases<U>(cond_bases_t(), source_data, target_data, ti);
}
};
@ -137,6 +138,6 @@ namespace sol {
} // namespace sol
#define SOL_BASE_CLASSES(T, ...) template <> struct ::sol::base<T> : ::std::true_type { typedef ::sol::types<__VA_ARGS__> type; };
//#define SOL_DERIVED_CLASSES(T, ...) template <> struct ::sol::derive<T> : ::std::true_type { typedef ::sol::types<__VA_ARGS__> type; };
#define SOL_DERIVED_CLASSES(T, ...) template <> struct ::sol::derive<T> : ::std::true_type { typedef ::sol::types<__VA_ARGS__> type; };
#endif // SOL_INHERITANCE_HPP

View File

@ -447,9 +447,7 @@ namespace sol {
void* memory = lua_touserdata(L, 1);
memory = align_usertype_unique_destructor(memory);
unique_destructor& dx = *static_cast<unique_destructor*>(memory);
memory = static_cast<void*>(static_cast<char*>(memory) + sizeof(unique_destructor));
memory = align_usertype_unique_tag<true>(memory);
memory = static_cast<void*>(static_cast<char*>(memory) + sizeof(unique_tag));
(dx)(memory);
return 0;
}

View File

@ -33,6 +33,7 @@ namespace stack {
struct qualified_getter<X, std::enable_if_t<
!std::is_reference<X>::value
&& is_unique_usertype<meta::unqualified_t<X>>::value
&& !std::is_void<typename unique_usertype_traits<meta::unqualified_t<X>>::template rebind_base<void>>::value
>> {
typedef unique_usertype_traits<meta::unqualified_t<X>> u_traits;
typedef typename u_traits::type T;

View File

@ -144,8 +144,10 @@ namespace stack {
template <typename T>
struct pusher<T, std::enable_if_t<is_unique_usertype<T>::value>> {
typedef typename unique_usertype_traits<T>::type P;
typedef typename unique_usertype_traits<T>::actual_type Real;
typedef unique_usertype_traits<T> u_traits;
typedef typename u_traits::type P;
typedef typename u_traits::actual_type Real;
typedef typename u_traits::template rebind_base<void> rebind_t;
template <typename Arg, meta::enable<std::is_base_of<Real, meta::unqualified_t<Arg>>> = meta::enabler>
static int push(lua_State* L, Arg&& arg) {