diff options
author | Chad Austin <chad@imvu.com> | 2013-04-15 22:26:21 -0700 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-18 20:08:15 +0300 |
commit | 426cbf616c7a4465e707d6f5cd0d11ab9ce27905 (patch) | |
tree | 60bf78741f58c566a8cd0076438f05134ce780a9 | |
parent | d2e6efdf4821ff1e9f16fc4884d398619c0d7a06 (diff) |
Support returning movable types
-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);
}
|