Last active
December 7, 2017 22:29
-
-
Save fhinkel/3596428e607e927b922615ba74152037 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
#include <napi.h> | |
#include <math.h> | |
namespace primes { | |
// Implementation of isPrime() and prime() omitted. See | |
// https://github.com/fhinkel/javascript-vs-native-addon-prime-numbers/blob/master/primes.cc | |
Napi::Value Method(const Napi::CallbackInfo& info) { | |
Napi::Env env = info.Env(); | |
int number = info[0].ToNumber().Int32Value(); | |
int res = primes::prime(env, number); | |
return Napi::Number::New(env, res); | |
} | |
Napi::Object Init(Napi::Env env, Napi::Object exports) { | |
exports.Set(Napi::String::New(env, "prime"), | |
Napi::Function::New(env, Method)); | |
return exports; | |
} | |
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init) | |
} // End namespace prime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment