2017-03-21 05:55:26 +08:00
|
|
|
#include <node_api.h>
|
2017-03-24 16:26:09 +08:00
|
|
|
#include "../common.h"
|
2017-03-21 05:55:26 +08:00
|
|
|
|
2017-03-24 16:26:09 +08:00
|
|
|
napi_value Add(napi_env env, napi_callback_info info) {
|
|
|
|
size_t argc = 2;
|
2017-03-21 05:55:26 +08:00
|
|
|
napi_value args[2];
|
2017-03-24 16:26:09 +08:00
|
|
|
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
|
|
|
|
|
|
|
|
NAPI_ASSERT(env, argc >= 2, "Wrong number of arguments");
|
2017-03-21 05:55:26 +08:00
|
|
|
|
|
|
|
napi_valuetype valuetype0;
|
2017-03-24 16:26:09 +08:00
|
|
|
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0));
|
2017-03-21 05:55:26 +08:00
|
|
|
|
|
|
|
napi_valuetype valuetype1;
|
2017-03-24 16:26:09 +08:00
|
|
|
NAPI_CALL(env, napi_typeof(env, args[1], &valuetype1));
|
2017-03-21 05:55:26 +08:00
|
|
|
|
2017-03-24 16:26:09 +08:00
|
|
|
NAPI_ASSERT(env, valuetype0 == napi_number && valuetype1 == napi_number,
|
2017-08-30 17:48:41 +08:00
|
|
|
"Wrong argument type. Numbers expected.");
|
2017-03-21 05:55:26 +08:00
|
|
|
|
|
|
|
double value0;
|
2017-03-24 16:26:09 +08:00
|
|
|
NAPI_CALL(env, napi_get_value_double(env, args[0], &value0));
|
2017-03-21 05:55:26 +08:00
|
|
|
|
|
|
|
double value1;
|
2017-03-24 16:26:09 +08:00
|
|
|
NAPI_CALL(env, napi_get_value_double(env, args[1], &value1));
|
2017-03-21 05:55:26 +08:00
|
|
|
|
|
|
|
napi_value sum;
|
2017-07-19 11:22:35 +08:00
|
|
|
NAPI_CALL(env, napi_create_double(env, value0 + value1, &sum));
|
2017-03-21 05:55:26 +08:00
|
|
|
|
2017-03-24 16:26:09 +08:00
|
|
|
return sum;
|
2017-03-21 05:55:26 +08:00
|
|
|
}
|
|
|
|
|
2017-08-30 17:48:41 +08:00
|
|
|
napi_value Init(napi_env env, napi_value exports) {
|
2017-03-24 16:26:09 +08:00
|
|
|
napi_property_descriptor desc = DECLARE_NAPI_PROPERTY("add", Add);
|
2017-08-30 17:48:41 +08:00
|
|
|
NAPI_CALL(env, napi_define_properties(env, exports, 1, &desc));
|
|
|
|
return exports;
|
2017-03-21 05:55:26 +08:00
|
|
|
}
|
|
|
|
|
2017-09-06 04:53:06 +08:00
|
|
|
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
|