diff options
author | Todd Lee <tlee@imvu.com> | 2013-01-08 00:31:46 -0800 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:22:54 +0300 |
commit | cd3be4e930df1358d9b07746f774a6ad00f3f39c (patch) | |
tree | e974c710f04c2910bb8d10ee1132ddb92f787a23 /system | |
parent | 5ea90f9345ebfb271dfd960f77fb0c669d30fca6 (diff) |
clean-up old interface binding implementation
Diffstat (limited to 'system')
-rwxr-xr-x | system/include/emscripten/bind.h | 74 | ||||
-rwxr-xr-x | system/lib/embind/bind.cpp | 4 |
2 files changed, 26 insertions, 52 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index a2c717f1..592928f5 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -902,58 +902,39 @@ namespace emscripten { } //////////////////////////////////////////////////////////////////////////////// - // INTERFACES + // NEW INTERFACE //////////////////////////////////////////////////////////////////////////////// - template<typename InterfaceType> - class wrapper : public InterfaceType { + class JSInterface { public: - wrapper() {} // to avoid error "call to implicitly deleted construrtor..." - - wrapper(InterfaceType* interface) { - cloneInterface(interface); + JSInterface(internal::EM_VAL handle) { + initialize(handle); } - // Not necessary in any example so far, but appeases a compiler warning. - virtual ~wrapper() {} - - typedef InterfaceType interface; + JSInterface(JSInterface& obj) { + jsobj = obj.jsobj; + } - template<class ConcreteWrapperType> - static std::shared_ptr<InterfaceType> cloneToSharedPtr(InterfaceType& i) { - ConcreteWrapperType* cw = new ConcreteWrapperType(&i); - InterfaceType* ip = dynamic_cast<InterfaceType*>(cw); - return std::shared_ptr<InterfaceType>(ip); + template<typename ReturnType, typename... Args> + ReturnType call(const char* name, Args... args) { + assertInitialized(); + return Caller<ReturnType, Args...>::call(*jsobj, name, args...); } - template<class ConcreteWrapperType> - static std::shared_ptr<ConcreteWrapperType> cloneToSharedWrapperPtr(InterfaceType& i) { - return std::make_shared<ConcreteWrapperType>(&i); + static std::shared_ptr<JSInterface> cloneToSharedPtr(JSInterface& i) { + return std::make_shared<JSInterface>(i); } + private: void initialize(internal::EM_VAL handle) { if (jsobj) { internal::_embind_fatal_error( "Cannot initialize interface wrapper twice", - typeid(InterfaceType).name()); + "JSInterface"); } jsobj = val::take_ownership(handle); } - template<typename ReturnType, typename... Args> - ReturnType call(const char* name, Args... args) { - assertInitialized(); - return Caller<ReturnType, Args...>::call(*jsobj, name, args...); - } - - protected: - void cloneInterface(InterfaceType* interface) { - // why dynamic_cast causes javascript crash? - wrapper<InterfaceType>* iw = static_cast<wrapper<InterfaceType>*>(interface); - jsobj = iw->jsobj; - } - - private: // this class only exists because you can't partially specialize function templates template<typename ReturnType, typename... Args> struct Caller { @@ -972,8 +953,7 @@ namespace emscripten { void assertInitialized() { if (!jsobj) { internal::_embind_fatal_error( - "Cannot invoke call on uninitialized interface wrapper.", - typeid(InterfaceType).name()); + "Cannot invoke call on uninitialized Javascript interface wrapper.", "JSInterface"); } } @@ -981,25 +961,17 @@ namespace emscripten { }; namespace internal { - template<typename WrapperType> - WrapperType* create_interface_wrapper(EM_VAL e) { - WrapperType* p = new WrapperType; - p->initialize(e); - return p; - } + extern JSInterface* create_js_interface(EM_VAL e); } - template<typename WrapperType> - class interface { + class register_js_interface { public: - typedef typename WrapperType::interface InterfaceType; - - interface(const char* name) { + register_js_interface() { _embind_register_interface( - internal::TypeID<InterfaceType>::get(), - name, - reinterpret_cast<internal::GenericFunction>(&internal::create_interface_wrapper<WrapperType>), - reinterpret_cast<internal::GenericFunction>(&internal::raw_destructor<WrapperType>)); + internal::TypeID<JSInterface>::get(), + "JSInterface", + reinterpret_cast<internal::GenericFunction>(&internal::create_js_interface), + reinterpret_cast<internal::GenericFunction>(&internal::raw_destructor<JSInterface>)); } }; } diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp index c69c4399..46924505 100755 --- a/system/lib/embind/bind.cpp +++ b/system/lib/embind/bind.cpp @@ -220,8 +220,10 @@ namespace emscripten { // developers, but perhaps the double underscore will scare them away from calling it.
function("__getDerivationPath", &__getDerivationPath);
}));
+ }
-
+ JSInterface* create_js_interface(EM_VAL e) {
+ return new JSInterface(e);
}
}
}
|