diff options
author | Chad Austin <chad@imvu.com> | 2013-02-25 18:04:45 -0800 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:24:08 +0300 |
commit | 176000557d9d25d6eb14511413e23321ea94e0aa (patch) | |
tree | 13f7a7c54df57e6501ed63b182998b4884cca1a0 | |
parent | 04d596f0408ccd7b591cf323bf2602b545155dcc (diff) |
allow non-member functions bound as methods.
-rwxr-xr-x | system/include/emscripten/bind.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 5806d57f..c83512c7 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -349,6 +349,32 @@ namespace emscripten { }; template<typename ClassType, typename ReturnType, typename... Args> + struct FunctionInvoker { + typedef ReturnType (FunctionPointer)(ClassType& ct, Args...); + static typename internal::BindingType<ReturnType>::WireType invoke( + ClassType* ptr, + FunctionPointer** function, + typename internal::BindingType<Args>::WireType... args + ) { + return internal::BindingType<ReturnType>::toWireType( + (*function)(*ptr, internal::BindingType<Args>::toWireType(args)...) + ); + } + }; + + template<typename ClassType, typename... Args> + struct FunctionInvoker<ClassType, void, Args...> { + typedef void (FunctionPointer)(ClassType& ct, Args...); + static void invoke( + ClassType* ptr, + FunctionPointer** function, + typename internal::BindingType<Args>::WireType... args + ) { + (*function)(*ptr, internal::BindingType<Args>::toWireType(args)...); + } + }; + + template<typename ClassType, typename ReturnType, typename... Args> struct MethodInvoker { typedef ReturnType (ClassType::*MemberPointer)(Args...); static typename internal::BindingType<ReturnType>::WireType invoke( @@ -717,6 +743,22 @@ namespace emscripten { return *this; } + template<typename ReturnType, typename... Args, typename... Policies> + class_& method(const char* methodName, ReturnType (*function)(ClassType& ptr, Args...), Policies...) { + using namespace internal; + + typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, Args...> args; + _embind_register_class_method( + TypeID<ClassType>::get(), + methodName, + args.count, + args.types, + reinterpret_cast<GenericFunction>(&FunctionInvoker<ClassType, ReturnType, Args...>::invoke), + sizeof(function), + &function); + return *this; + } + template<typename FieldType> class_& field(const char* fieldName, FieldType ClassType::*field) { using namespace internal; |