From de48fdc5b028df627b7070c17d37479654f71a13 Mon Sep 17 00:00:00 2001 From: Chad Austin Date: Mon, 1 Apr 2013 17:54:55 -0700 Subject: [PATCH] Further generalize support for tuple elements, and in the meantime, fix a bug that made it into one variant of the function but not the other... --- src/embind/embind.js | 38 +++++--------------------------- system/include/emscripten/bind.h | 17 ++++++-------- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/src/embind/embind.js b/src/embind/embind.js index 845bf98bb..3daa4b018 100755 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -387,37 +387,6 @@ function __embind_register_tuple(rawType, name, rawConstructor, rawDestructor) { } function __embind_register_tuple_element( - rawTupleType, - rawType, - getter, - setter, - context -) { - getter = FUNCTION_TABLE[getter]; - setter = FUNCTION_TABLE[setter]; - var tupleType = requireRegisteredType(rawTupleType, 'tuple'); - - var index = tupleType.elements.length; - tupleType.elements.push(undefined); - - // TODO: test incomplete registration of value tuples - whenDependentTypesAreResolved([], [rawType], function(type) { - type = type[0]; - tupleType.elements[index] = { - read: function(ptr) { - return type.fromWireType(getter(context, ptr)); - }, - write: function(ptr, o) { - var destructors = []; - setter(context, ptr, type.toWireType(destructors, o)); - runDestructors(destructors); - } - }; - return []; - }); -} - -function __embind_register_tuple_element_accessor( rawTupleType, getterReturnType, getter, @@ -430,11 +399,14 @@ function __embind_register_tuple_element_accessor( getter = FUNCTION_TABLE[getter]; setter = FUNCTION_TABLE[setter]; + var index = tupleType.elements.length; + tupleType.elements.push(undefined); + // TODO: test incomplete registration of value tuples whenDependentTypesAreResolved([], [getterReturnType, setterArgumentType], function(types) { var getterReturnType = types[0]; var setterArgumentType = types[1]; - tupleType.elements.push({ + tupleType.elements[index] = { read: function(ptr) { return getterReturnType.fromWireType( getter( @@ -449,7 +421,7 @@ function __embind_register_tuple_element_accessor( setterArgumentType.toWireType(destructors, o)); runDestructors(destructors); } - }); + }; return []; }); } diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index a002ca239..a5530744b 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -69,13 +69,6 @@ namespace emscripten { GenericFunction destructor); void _embind_register_tuple_element( - TYPEID tupleType, - TYPEID elementType, - GenericFunction getter, - GenericFunction setter, - void* context); - - void _embind_register_tuple_element_accessor( TYPEID tupleType, TYPEID getterReturnType, GenericFunction staticGetter, @@ -414,8 +407,12 @@ namespace emscripten { _embind_register_tuple_element( TypeID::get(), TypeID::get(), - reinterpret_cast(&MemberAccess::getWire), - reinterpret_cast(&MemberAccess::setWire), + reinterpret_cast( + &MemberAccess::getWire), + getContext(field), + TypeID::get(), + reinterpret_cast( + &MemberAccess::setWire), getContext(field)); return *this; } @@ -426,7 +423,7 @@ namespace emscripten { void (*setter)(ClassType&, SetterArgumentType) ) { using namespace internal; - _embind_register_tuple_element_accessor( + _embind_register_tuple_element( TypeID::get(), TypeID::get(), reinterpret_cast(