首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用N-API将C++的BigInt类型返回给javascript?

如何使用N-API将C++的BigInt类型返回给javascript?
EN

Stack Overflow用户
提问于 2019-02-26 13:36:36
回答 1查看 394关注 0票数 4

我使用这个https://github.com/nodejs/node-addon-api/blob/master/doc/bigint.md文档作为从c++返回bigint的引用,但我得到了以下错误:

代码语言:javascript
复制
error: ‘BigInt’ in namespace ‘Napi’ does not name a type
     Napi::BigInt HelloWrapped(const Napi::CallbackInfo& info);

以下是我的源代码:

代码语言:javascript
复制
#include <napi.h>
#include "bigintexample.h"

std::int64_t bigintexample::hello() {
    return 1234;
}

Napi::BigInt bigintexample::HelloWrapped(const Napi::CallbackInfo& info) {
    Napi::Env env = info.Env();
    Napi::BigInt returnValue = Napi::BigInt::New(env, bigintexample::hello());

    return returnValue;
}


Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
    exports.Set("hello", Napi::Function::New(env, bigintexample::HelloWrapped));
    return exports;
}


NODE_API_MODULE(NODE_GYP_MODULE_NAME, InitAll)

在napi.h中,只有当NAPI_VERSION定义大于2147483646时,BigInt功能才可用。当我将NAPI_VERSION定义设置为一个大于2147483646的数字时,我得到以下错误消息

代码语言:javascript
复制
/home/user/bigint-napi/node_modules/node-addon-api/napi-inl.h:573:24: error: ‘napi_create_bigint_int64’ was not declared in this scope
   napi_status status = napi_create_bigint_int64(env, val, &value);
EN

回答 1

Stack Overflow用户

发布于 2019-02-27 13:10:54

通过添加define: NAPI_EXPERIMENTAL并删除NAPI_VERSION定义解决了这个问题

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54879033

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档