diff options
author | Chad Austin <chad@imvu.com> | 2013-04-01 18:47:55 -0700 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:27:03 +0300 |
commit | e5af621a189f729d8c1513f739a6a085adf39842 (patch) | |
tree | bc810bfc5553cfbcab494ad996ab006ccee75991 /system | |
parent | de48fdc5b028df627b7070c17d37479654f71a13 (diff) |
Generalize support for struct fields
Diffstat (limited to 'system')
-rwxr-xr-x | system/include/emscripten/bind.h | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index a5530744..fe0c9711 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -71,25 +71,27 @@ namespace emscripten { void _embind_register_tuple_element( TYPEID tupleType, TYPEID getterReturnType, - GenericFunction staticGetter, + GenericFunction getter, void* getterContext, TYPEID setterArgumentType, - GenericFunction staticSetter, + GenericFunction setter, void* setterContext); void _embind_register_struct( TYPEID structType, - const char* name, + const char* fieldName, GenericFunction constructor, GenericFunction destructor); void _embind_register_struct_field( TYPEID structType, - const char* name, - TYPEID fieldType, + const char* fieldName, + TYPEID getterReturnType, GenericFunction getter, + void* getterContext, + TYPEID setterArgumentType, GenericFunction setter, - void* context); + void* setterContext); void _embind_register_smart_ptr( TYPEID pointerType, @@ -462,11 +464,38 @@ namespace emscripten { TypeID<ClassType>::get(), fieldName, TypeID<FieldType>::get(), - reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, FieldType>::getWire), - reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, FieldType>::setWire), + reinterpret_cast<GenericFunction>( + &MemberAccess<ClassType, FieldType>::getWire), + getContext(field), + TypeID<FieldType>::get(), + reinterpret_cast<GenericFunction>( + &MemberAccess<ClassType, FieldType>::setWire), getContext(field)); return *this; } + + template<typename GetterReturnType, typename SetterArgumentType> + value_struct& field( + const char* fieldName, + GetterReturnType (*getter)(const ClassType&), + void (*setter)(ClassType&, SetterArgumentType) + ) { + using namespace internal; + _embind_register_struct_field( + TypeID<ClassType>::get(), + fieldName, + TypeID<GetterReturnType>::get(), + reinterpret_cast<GenericFunction>( + &MemberAccess<ClassType, GetterReturnType> + ::template propertyGet<GetterReturnType(*)(const ClassType&)>), + getContext(getter), + TypeID<SetterArgumentType>::get(), + reinterpret_cast<GenericFunction>( + &MemberAccess<ClassType, SetterArgumentType> + ::template propertySet<void(*)(ClassType&, SetterArgumentType)>), + getContext(setter)); + return *this; + } }; //////////////////////////////////////////////////////////////////////////////// |