簡體   English   中英

如何使用N-API將BigInt類型從C ++返回到javascript?

[英]How do I return a BigInt type from C++ to javascript using N-API?

我正在使用此https://github.com/nodejs/node-addon-api/blob/master/doc/bigint.md文檔作為從c ++返回bigint的參考,但是我收到以下錯誤:

error: ‘BigInt’ in namespace ‘Napi’ does not name a type
     Napi::BigInt HelloWrapped(const Napi::CallbackInfo& info);

這是我的源代碼:

#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中,BigInt功能僅在NAPI_VERSION定義大於2147483646時可用。當我將NAPI_VERSION定義設置為高於2147483646的數字時,我收到以下錯誤消息

/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);

通過添加define:NAPI_EXPERIMENTAL並刪除NAPI_VERSION定義來解決它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM