Created
December 31, 2015 05:26
-
-
Save xaxxon/ba231db4647822332e4b to your computer and use it in GitHub Desktop.
This file contains 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 T> | |
struct CastToNative {}; | |
template<> | |
struct CastToNative<int> { | |
int operator()(Local<Value> value){return value->ToInteger()->Value();} | |
}; | |
template<> | |
struct CastToNative<char *> { | |
char * operator()(Local<Value> value){return *v8::String::Utf8Value(value);} | |
}; | |
template<> | |
struct CastToNative<const char *> { | |
const char * operator()(Local<Value> value){return CastToNative<char *>()(value);} | |
}; | |
template<> | |
struct CastToNative<double> { | |
double operator()(Local<Value> value){return value->ToNumber()->Value();} | |
}; | |
template<> | |
struct CastToNative<std::string> { | |
std::string operator()(Local<Value> value){return std::string(CastToNative<char *>()(value));} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this the right/best way to unbox a type? other than maybe using a macro for DRY?