Skip to content

Instantly share code, notes, and snippets.

@fhinkel
Last active December 7, 2017 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhinkel/3596428e607e927b922615ba74152037 to your computer and use it in GitHub Desktop.
Save fhinkel/3596428e607e927b922615ba74152037 to your computer and use it in GitHub Desktop.
#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