diff options
author | Chad Austin <chad@imvu.com> | 2013-04-17 17:51:24 -0700 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-18 20:08:41 +0300 |
commit | a02d08a15f853665cee193c7f21e84f48bee8845 (patch) | |
tree | 5d36ca5d1787c613ae34d48dcf6fdd0096cf76e6 | |
parent | b4cc2e135b1d611fa54c28bf05aada1657c97b30 (diff) |
Make select_overload work for member functions
-rwxr-xr-x | system/include/emscripten/bind.h | 12 | ||||
-rw-r--r-- | tests/embind/embind_test.cpp | 24 |
2 files changed, 25 insertions, 11 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index cd35a238..4d2f4ac8 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -230,6 +230,18 @@ namespace emscripten { } namespace internal { + template<typename ClassType, typename Signature> + struct MemberFunctionType { + typedef Signature (ClassType::*type); + }; + } + + template<typename Signature, typename ClassType> + typename internal::MemberFunctionType<ClassType, Signature>::type select_overload(Signature (ClassType::*fn)) { + return fn; + } + + namespace internal { template<typename ReturnType, typename... Args> struct Invoker { static typename internal::BindingType<ReturnType>::WireType invoke( diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index e969f9d8..f2359955 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -1925,8 +1925,8 @@ EMSCRIPTEN_BINDINGS(tests) { function("long_to_string", &long_to_string);
function("unsigned_long_to_string", &unsigned_long_to_string);
- function("overloaded_function", (int(*)(int))&overloaded_function);
- function("overloaded_function", (int(*)(int, int))&overloaded_function);
+ function("overloaded_function", select_overload<int(int)>(&overloaded_function));
+ function("overloaded_function", select_overload<int(int, int)>(&overloaded_function));
class_<MultipleCtors>("MultipleCtors")
.constructor<int>()
@@ -1936,19 +1936,21 @@ EMSCRIPTEN_BINDINGS(tests) { class_<MultipleOverloads>("MultipleOverloads")
.constructor<>()
- .function("Func", (int(MultipleOverloads::*)(int))&MultipleOverloads::Func)
- .function("Func", (int(MultipleOverloads::*)(int,int))&MultipleOverloads::Func)
+ .function("Func", select_overload<int(int)>(&MultipleOverloads::Func))
+ .function("Func", select_overload<int(int, int)>(&MultipleOverloads::Func))
.function("WhichFuncCalled", &MultipleOverloads::WhichFuncCalled)
- .class_function("StaticFunc", (int(*)(int))&MultipleOverloads::StaticFunc)
- .class_function("StaticFunc", (int(*)(int,int))&MultipleOverloads::StaticFunc)
- .class_function("WhichStaticFuncCalled", &MultipleOverloads::WhichStaticFuncCalled);
+ .class_function("StaticFunc", select_overload<int(int)>(&MultipleOverloads::StaticFunc))
+ .class_function("StaticFunc", select_overload<int(int,int)>(&MultipleOverloads::StaticFunc))
+ .class_function("WhichStaticFuncCalled", &MultipleOverloads::WhichStaticFuncCalled)
+ ;
class_<MultipleOverloadsDerived, base<MultipleOverloads> >("MultipleOverloadsDerived")
.constructor<>()
- .function("Func", (int(MultipleOverloadsDerived::*)(int,int,int))&MultipleOverloadsDerived::Func)
- .function("Func", (int(MultipleOverloadsDerived::*)(int,int,int,int))&MultipleOverloadsDerived::Func)
- .class_function("StaticFunc", (int(*)(int,int,int))&MultipleOverloadsDerived::StaticFunc)
- .class_function("StaticFunc", (int(*)(int,int,int,int))&MultipleOverloadsDerived::StaticFunc);
+ .function("Func", select_overload<int(int,int,int)>(&MultipleOverloadsDerived::Func))
+ .function("Func", select_overload<int(int,int,int,int)>(&MultipleOverloadsDerived::Func))
+ .class_function("StaticFunc", select_overload<int(int,int,int)>(&MultipleOverloadsDerived::StaticFunc))
+ .class_function("StaticFunc", select_overload<int(int,int,int,int)>(&MultipleOverloadsDerived::StaticFunc))
+ ;
}
// tests for out-of-order registration
|