-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadd.cpp
33 lines (29 loc) · 884 Bytes
/
add.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* This is free and unencumbered software released into the public domain.
* For more information, please refer to the LICENSE file in the root directory
* or at <http://unlicense.org/>
*/
#include "registerNatives.h"
using namespace facebook;
/// A very complicated function that adds all its arguments, which must be
/// numbers, together.
static jsi::Value hostAdd(
jsi::Runtime &rt,
const jsi::Value &,
const jsi::Value *args,
size_t count) {
double sum = 0;
for (size_t i = 0; i < count; ++i) {
if (!args[i].isNumber())
throw jsi::JSError(rt, "Argument must be a number");
sum += args[i].asNumber();
}
return sum;
}
extern "C" void registerNatives(jsi::Runtime &rt) {
rt.global().setProperty(
rt,
"add",
jsi::Function::createFromHostFunction(
rt, jsi::PropNameID::forAscii(rt, "add"), 2, hostAdd));
}