diff options
author | Chad Austin <caustin@gmail.com> | 2014-03-23 13:28:44 -0700 |
---|---|---|
committer | Chad Austin <chad@chadaustin.me> | 2014-03-28 23:56:40 -0700 |
commit | bb34f6aaa0043e39d43b684f78099712b79026c2 (patch) | |
tree | 1a446e38ad31d6122490383c302bf5547e9932cd /system/include | |
parent | 6291f97039f94eb2eaeae7535a7dbe9c6ff8bbe5 (diff) |
It appears we can use doubles as generic wire types.
Diffstat (limited to 'system/include')
-rw-r--r-- | system/include/emscripten/val.h | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h index 501e927d..9b1ad70d 100644 --- a/system/include/emscripten/val.h +++ b/system/include/emscripten/val.h @@ -35,7 +35,7 @@ namespace emscripten { EM_VAL _emval_get_module_property(const char* name); EM_VAL _emval_get_property(EM_VAL object, EM_VAL key); void _emval_set_property(EM_VAL object, EM_VAL key, EM_VAL value); - void _emval_as(EM_VAL value, TYPEID returnType, void* result, EM_DESTRUCTORS* destructors); + double _emval_as(EM_VAL value, TYPEID returnType, EM_DESTRUCTORS* destructors); EM_VAL _emval_call( EM_VAL value, @@ -95,6 +95,25 @@ namespace emscripten { EM_DESTRUCTORS destructors; }; + template<typename WireType> + struct GenericWireTypeConverter { + static WireType from(double wt) { + return static_cast<WireType>(wt); + } + }; + + template<typename Pointee> + struct GenericWireTypeConverter<Pointee*> { + static Pointee* from(double wt) { + return reinterpret_cast<Pointee*>(static_cast<uintptr_t>(wt)); + } + }; + + template<typename WireType> + WireType fromGenericWireType(double wt) { + return GenericWireTypeConverter<WireType>::from(wt); + } + template<typename ReturnType, typename... Args> struct MethodCaller { static ReturnType call(EM_VAL handle, const char* methodName, Args&&... args) { @@ -286,9 +305,11 @@ namespace emscripten { typedef BindingType<T> BT; - typename BT::WireType result; EM_DESTRUCTORS destructors; - _emval_as(handle, TypeID<T>::get(), &result, &destructors); + auto result = fromGenericWireType<typename BindingType<T>::WireType>(_emval_as( + handle, + TypeID<T>::get(), + &destructors)); DestructorsRunner dr(destructors); return BT::fromWireType(result); } |