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...
This commit is contained in:
Родитель
e30dd3017a
Коммит
de48fdc5b0
|
@ -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 [];
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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<ClassType>::get(),
|
||||
TypeID<ElementType>::get(),
|
||||
reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, ElementType>::getWire),
|
||||
reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, ElementType>::setWire),
|
||||
reinterpret_cast<GenericFunction>(
|
||||
&MemberAccess<ClassType, ElementType>::getWire),
|
||||
getContext(field),
|
||||
TypeID<ElementType>::get(),
|
||||
reinterpret_cast<GenericFunction>(
|
||||
&MemberAccess<ClassType, ElementType>::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<ClassType>::get(),
|
||||
TypeID<GetterReturnType>::get(),
|
||||
reinterpret_cast<GenericFunction>(
|
||||
|
|
Загрузка…
Ссылка в новой задаче