xref: /third_party/decimal.js/decimal.cpp (revision 023dd3b8)
1/*!
2 *  decimal.js v10.4.3
3 *  An arbitrary-precision Decimal type for JavaScript.
4 *  https://github.com/MikeMcl/decimal.js
5 *  Copyright (c) 2024 Huawei Device Co., Ltd.
6 *  MIT Licence
7 */
8
9#include "native_engine/native_engine.h"
10
11extern const char _binary_decimal_mjs_start[];
12extern const char _binary_decimal_mjs_end[];
13extern const char _binary_decimal_abc_start[];
14extern const char _binary_decimal_abc_end[];
15
16// Napi get mjs code function
17extern "C" __attribute__((visibility("default")))
18void NAPI_arkts_math_Decimal_GetMJSCode(const char **buf, int *buflen)
19{
20    if (buf != nullptr) {
21        *buf = _binary_decimal_mjs_start;
22    }
23    if (buflen != nullptr) {
24        *buflen = _binary_decimal_mjs_end - _binary_decimal_mjs_start;
25    }
26}
27
28// Napi get abc code function
29extern "C" __attribute__((visibility("default")))
30void NAPI_arkts_math_Decimal_GetABCCode(const char **buf, int *buflen)
31{
32    if (buf != nullptr) {
33        *buf = _binary_decimal_abc_start;
34    }
35    if (buflen != nullptr) {
36        *buflen = _binary_decimal_abc_end - _binary_decimal_abc_start;
37    }
38}
39
40/*
41 * Module define
42 */
43static napi_module DecimalModule = {
44    .nm_filename = nullptr,
45    .nm_modname = "arkts.math.Decimal",
46};
47extern "C" __attribute__((constructor)) void DecimalRegisterModule(void)
48{
49    napi_module_register(&DecimalModule);
50}
51