diff options
-rwxr-xr-x | system/include/emscripten/wire.h | 14 | ||||
-rw-r--r-- | tests/embind/embind_test.cpp | 11 |
2 files changed, 22 insertions, 3 deletions
diff --git a/system/include/emscripten/wire.h b/system/include/emscripten/wire.h index 0e8334e8..6fb15fc7 100755 --- a/system/include/emscripten/wire.h +++ b/system/include/emscripten/wire.h @@ -206,6 +206,10 @@ namespace emscripten { }; template<typename T> + struct BindingType<T&> : public BindingType<T> { + }; + + template<typename T> struct BindingType<const T&> : public BindingType<T> { }; @@ -236,10 +240,14 @@ namespace emscripten { typedef typename std::remove_reference<T>::type ActualT; typedef ActualT* WireType; - static WireType toWireType(T v) { + static WireType toWireType(const T& v) { return new T(v); } + static WireType toWireType(T&& v) { + return new T(std::forward<T>(v)); + } + static ActualT& fromWireType(WireType p) { return *p; } @@ -282,8 +290,8 @@ namespace emscripten { {}; template<typename T> - auto toWireType(const T& v) -> typename BindingType<T>::WireType { - return BindingType<T>::toWireType(v); + auto toWireType(T&& v) -> typename BindingType<T>::WireType { + return BindingType<T>::toWireType(std::forward<T>(v)); } template<typename T> diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 86d850e0..ce133112 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -2088,15 +2088,26 @@ class Noncopyable { public:
Noncopyable() {}
+ Noncopyable(Noncopyable&& other) {
+ other.valid = false;
+ }
std::string method() const {
return "foo";
}
+
+ bool valid = true;
};
+Noncopyable getNoncopyable() {
+ return Noncopyable();
+}
+
EMSCRIPTEN_BINDINGS(noncopyable) {
class_<Noncopyable>("Noncopyable")
.constructor<>()
.function("method", &Noncopyable::method)
;
+
+ function("getNoncopyable", &getNoncopyable);
}
|