-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: add Env::GetModuleFileName #1327
Conversation
*: |
#if NAPI_VERSION > 8 | ||
inline std::string_view Env::GetModuleFileName() const { | ||
const char* result; | ||
napi_status status = node_api_get_module_file_name(_env, &result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node.js v16.x (and add-ons compiled with the common.gypi
shipped with Node.js) is still compiled with C++14, however std::string_view
is available since c++17. I think we should avoid using c++17 features here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhmm mhmm that makes sense ... So then would we prefer the alternative of node-addon-api returning a new std::string
by copying the const char* result
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be good to return the const char* result
? If needed, copying the result with std::string
is fairly easy.
- Do not use `std::string_view` since not available in C++14 (Node v16)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR-URL: #1327 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com
Landed in b83e453 |
PR-URL: nodejs/node-addon-api#1327 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com
Adds wrapper for
Napi::Env::GetModuleFileName()
from release of Node-API v9.