Created
December 30, 2015 03:37
-
-
Save xaxxon/4371d36837ce0c0a3c91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename METHOD_TYPE> | |
struct RunMethod {}; | |
template<typename RETURN_TYPE, typename CLASS_TYPE, typename ... PARAMETERS> | |
struct RunMethod<RETURN_TYPE(CLASS_TYPE::*)(PARAMETERS...)>{ | |
typedef RETURN_TYPE(CLASS_TYPE::*METHOD_TYPE)(PARAMETERS...); | |
CLASS_TYPE object; | |
METHOD_TYPE method; | |
RunMethod(CLASS_TYPE object, METHOD_TYPE method) : object(object), method(method) {} | |
void operator()(const v8::FunctionCallbackInfo<v8::Value> & info, PARAMETERS... parameters) { | |
RETURN_TYPE return_value = (object.*method)(parameters...); | |
CastToJS<RETURN_TYPE> cast; | |
info.GetReturnValue().Set(cast(info.GetIsolate(), return_value)); | |
} | |
}; | |
template<typename CLASS_TYPE, typename ... PARAMETERS> | |
struct RunMethod<void(CLASS_TYPE::*)(PARAMETERS...)> { | |
typedef void(CLASS_TYPE::*METHOD_TYPE)(PARAMETERS...); | |
CLASS_TYPE object; | |
METHOD_TYPE method; | |
RunMethod(CLASS_TYPE object, METHOD_TYPE method) : object(object), method(method) {} | |
void operator()(const v8::FunctionCallbackInfo<v8::Value> &, PARAMETERS... parameters) { | |
(object.*method)(parameters...); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should I create a separate templatized base class for both of these to inherit from that has "object" and "method" as well as a pure virtual operator() ?