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 | |
parent | 6291f97039f94eb2eaeae7535a7dbe9c6ff8bbe5 (diff) |
It appears we can use doubles as generic wire types.
-rw-r--r-- | src/embind/emval.js | 9 | ||||
-rw-r--r-- | system/include/emscripten/val.h | 27 |
2 files changed, 28 insertions, 8 deletions
diff --git a/src/embind/emval.js b/src/embind/emval.js index 96d477c1..f0ca9b9b 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -187,16 +187,15 @@ function __emval_set_property(handle, key, value) { _emval_handle_array[handle].value[_emval_handle_array[key].value] = _emval_handle_array[value].value; } -function __emval_as(handle, returnType, result, destructorsRef) { +function __emval_as(handle, returnType, destructorsRef) { requireHandle(handle); returnType = requireRegisteredType(returnType, 'emval::as'); var destructors = []; var rd = __emval_register(destructors); HEAP32[destructorsRef >> 2] = rd; - returnType.writeValueToPointer( - _emval_handle_array[handle].value, - result, - destructors); + return returnType['toWireType']( + destructors, + _emval_handle_array[handle].value); } function parseParameters(argCount, argTypes, argWireTypes) { 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); } |