Skip to content

Commit 492d61c

Browse files
author
Aidan Lee
committed
Add native struct wrapping back
1 parent 4673089 commit 492d61c

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

include/hx/Invoker.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ namespace hx
3838
template<class T>
3939
struct ConversionTrait
4040
{
41-
inline static Dynamic toDynamic(T v) { return Dynamic{ v }; }
41+
inline static Dynamic _hx_struct(T value, std::true_type)
42+
{
43+
return Dynamic{ value };
44+
}
45+
inline static Dynamic _hx_struct(T value, std::false_type)
46+
{
47+
return ::cpp::Struct<T>(value);
48+
}
49+
50+
inline static Dynamic toDynamic(T v) { return _hx_struct(v, std::is_constructible<Dynamic, T>{}); }
4251
inline static T fromDynamic(Dynamic d) { return T{ d }; }
4352
};
4453

@@ -52,42 +61,42 @@ namespace hx
5261
template<class T>
5362
struct ConversionTrait<::cpp::Pointer<T>>
5463
{
55-
inline static Dynamic toDynamic(::cpp::Pointer<T> v) { return Dynamic{ v }; }
64+
inline static Dynamic toDynamic(::cpp::Pointer<T> v) { return v; }
5665
inline static ::cpp::Pointer<T> fromDynamic(Dynamic d) { return cpp::Pointer<T>(d); }
5766
};
5867

5968
template<class T>
6069
struct ConversionTrait<::cpp::Struct<T>>
6170
{
62-
inline static Dynamic toDynamic(::cpp::Struct<T> v) { return Dynamic{ v }; }
71+
inline static Dynamic toDynamic(::cpp::Struct<T> v) { return v; }
6372
inline static ::cpp::Struct<T> fromDynamic(Dynamic d) { return cpp::Struct<T>(d); }
6473
};
6574

6675
template<class T>
6776
struct ConversionTrait<::cpp::marshal::ValueReference<T>>
6877
{
69-
inline static Dynamic toDynamic(::cpp::marshal::ValueReference<T> v) { return Dynamic{ v }; }
78+
inline static Dynamic toDynamic(::cpp::marshal::ValueReference<T> v) { return v; }
7079
inline static ::cpp::marshal::ValueReference<T> fromDynamic(Dynamic d) { return ::cpp::marshal::ValueReference<T>{ ::cpp::marshal::ValueType<T>{ d } }; }
7180
};
7281

7382
template<class T>
7483
struct ConversionTrait<::cpp::marshal::ValueType<T>>
7584
{
76-
inline static Dynamic toDynamic(::cpp::marshal::ValueType<T> v) { return Dynamic{ v }; }
85+
inline static Dynamic toDynamic(::cpp::marshal::ValueType<T> v) { return ::cpp::marshal::ValueReference<T>{ v }; }
7786
inline static ::cpp::marshal::ValueType<T> fromDynamic(Dynamic d) { return ::cpp::marshal::ValueType<T>{ d }; }
7887
};
7988

8089
template<class T>
8190
struct ConversionTrait<::cpp::marshal::PointerReference<T>>
8291
{
83-
inline static Dynamic toDynamic(::cpp::marshal::PointerReference<T> v) { return Dynamic{ v }; }
92+
inline static Dynamic toDynamic(::cpp::marshal::PointerReference<T> v) { return v; }
8493
inline static ::cpp::marshal::PointerReference<T> fromDynamic(Dynamic d) { return ::cpp::marshal::PointerReference<T>{ ::cpp::marshal::PointerType<T>{ d } }; }
8594
};
8695

8796
template<class T>
8897
struct ConversionTrait<::cpp::marshal::PointerType<T>>
8998
{
90-
inline static Dynamic toDynamic(::cpp::marshal::PointerType<T> v) { return Dynamic{ v }; }
99+
inline static Dynamic toDynamic(::cpp::marshal::PointerType<T> v) { return ::cpp::marshal::PointerReference<T>{ v }; }
91100
inline static ::cpp::marshal::PointerType<T> fromDynamic(Dynamic d) { return ::cpp::marshal::PointerType<T>{ d }; }
92101
};
93102

0 commit comments

Comments
 (0)