aboutsummaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rwxr-xr-xsystem/include/emscripten/bind.h34
-rwxr-xr-xsystem/lib/embind/bind.cpp10
2 files changed, 30 insertions, 14 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h
index cbc5cb8e..24a7bf71 100755
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -611,19 +611,45 @@ namespace emscripten {
#define EMSCRIPTEN_WRAPPER(T) \
T(const ::emscripten::val& v): wrapper(v) {}
- // TODO: support base class
- template<typename ClassType>
+ namespace internal {
+ struct NoBaseClass {
+ static TYPEID get() {
+ return 0;
+ }
+
+ template<typename ClassType>
+ static void verify() {
+ }
+ };
+ }
+
+ template<typename BaseClass>
+ struct base {
+ static internal::TYPEID get() {
+ return internal::TypeID<BaseClass>::get();
+ }
+
+ template<typename ClassType>
+ static void verify() {
+ static_assert(!std::is_same<ClassType, BaseClass>::value, "Base must not have same type as class");
+ static_assert(std::is_base_of<BaseClass, ClassType>::value, "Derived class must derive from base");
+ }
+ };
+
+ template<typename ClassType, typename BaseSpecifier = internal::NoBaseClass>
class class_ {
public:
class_(const char* name) {
using namespace internal;
+ BaseSpecifier::template verify<ClassType>();
+
registerStandardTypes();
_embind_register_class(
TypeID<ClassType>::get(),
TypeID<AllowedRawPointer<ClassType>>::get(),
TypeID<AllowedRawPointer<const ClassType>>::get(),
- 0,
+ BaseSpecifier::get(),
std::is_polymorphic<ClassType>::value,
name,
reinterpret_cast<GenericFunction>(&raw_destructor<ClassType>));
@@ -672,7 +698,7 @@ namespace emscripten {
using namespace internal;
// TODO: unique or anonymous name
- class_<WrapperType>("WrapperType")
+ class_<WrapperType, base<ClassType>>("WrapperType")
.template constructor<val>()
;
diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp
index 081db2cd..cbff7cf1 100755
--- a/system/lib/embind/bind.cpp
+++ b/system/lib/embind/bind.cpp
@@ -133,15 +133,6 @@ namespace emscripten {
return derivationPath;
}
- std::vector<int> __getBaseClasses(int tp) {
- std::vector<const __cxxabiv1::__class_type_info*> baseTypes = __internalGetBaseClasses((const __cxxabiv1::__class_type_info*)tp);
- std::vector<int> bases;
- for (int j = 0; j < baseTypes.size(); j++) {
- bases.emplace_back((int)baseTypes[j]);
- }
- return bases;
- }
-
extern "C" {
// These three routines constitute an extension to the compiler's support for dynamic type conversion.
// They are used by embind.js to implement automatic downcasting of return values which are pointers to
@@ -229,7 +220,6 @@ namespace emscripten {
// conversion for the return value. This has the unfortunate side-effect of exposing it to third party
// developers, but perhaps the double underscore will scare them away from calling it.
function("__getDerivationPath", &__getDerivationPath);
- function("__getBaseClasses", &__getBaseClasses);
function("__peek32", &__peek32, allow_raw_pointers());
}));
}