diff options
author | Chad Austin <chad@imvu.com> | 2013-04-17 16:56:41 -0700 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-18 20:08:39 +0300 |
commit | f25a4c9d196b5436bf526308cb9d771f3610dd81 (patch) | |
tree | 8095afc9d764dfa09c33533246b9981754befdfc /system | |
parent | 905bbbf350aa1dc475873db681d952b085fd940d (diff) |
Add support for read-only properties.
Diffstat (limited to 'system')
-rwxr-xr-x | system/include/emscripten/bind.h | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index a3886031..0bb21290 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -991,7 +991,23 @@ namespace emscripten { return *this; } - template<typename FieldType> + template<typename FieldType, typename = typename std::enable_if<!std::is_function<FieldType>::value>::type> + class_& property(const char* fieldName, const FieldType ClassType::*field) { + using namespace internal; + + _embind_register_class_property( + TypeID<ClassType>::get(), + fieldName, + TypeID<FieldType>::get(), + reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, FieldType>::template getWire<ClassType>), + getContext(field), + 0, + 0, + 0); + return *this; + } + + template<typename FieldType, typename = typename std::enable_if<!std::is_function<FieldType>::value>::type> class_& property(const char* fieldName, FieldType ClassType::*field) { using namespace internal; @@ -1007,6 +1023,22 @@ namespace emscripten { return *this; } + template<typename Getter> + class_& property(const char* fieldName, Getter getter) { + using namespace internal; + typedef GetterPolicy<Getter> GP; + _embind_register_class_property( + TypeID<ClassType>::get(), + fieldName, + TypeID<typename GP::ReturnType>::get(), + reinterpret_cast<GenericFunction>(&GP::template get<ClassType>), + GP::getContext(getter), + 0, + 0, + 0); + return *this; + } + template<typename Getter, typename Setter> class_& property(const char* fieldName, Getter getter, Setter setter) { using namespace internal; |