Skip to content

Commit 732c46c

Browse files
alshdavidvmoroz
andcommitted
node-api: minimal C node_embedding_api function
Co-authored-by: vmoroz <[email protected]>
1 parent 9acf6af commit 732c46c

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

node.gyp

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
113113
'src/node_dir.cc',
114114
'src/node_dotenv.cc',
115115
'src/node_env_var.cc',
116+
'src/node_embedding_api.cc',
117+
'src/node_embedding_api.h',
116118
'src/node_errors.cc',
117119
'src/node_external_reference.cc',
118120
'src/node_file.cc',

src/node_embedding_api.cc

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Description: C-based API for embedding Node.js.
3+
//
4+
// !!! WARNING !!! WARNING !!! WARNING !!!
5+
// This is a new API and is subject to change.
6+
// While it is C-based, it is not ABI safe yet.
7+
// Consider all functions and data structures as experimental.
8+
// !!! WARNING !!! WARNING !!! WARNING !!!
9+
//
10+
// This file contains the C-based API for embedding Node.js in a host
11+
// application. The API is designed to be used by applications that want to
12+
// embed Node.js as a shared library (.so or .dll) and can interop with
13+
// C-based API.
14+
//
15+
16+
17+
#include "node_embedding_api.h"
18+
#include "node.h"
19+
20+
EXTERN_C_START
21+
22+
int32_t NAPI_CDECL node_embedding_main(int32_t argc, char* argv[]) {
23+
return node::Start(argc, argv);
24+
}
25+
26+
EXTERN_C_END

src/node_embedding_api.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Description: C-based API for embedding Node.js.
3+
//
4+
// !!! WARNING !!! WARNING !!! WARNING !!!
5+
// This is a new API and is subject to change.
6+
// While it is C-based, it is not ABI safe yet.
7+
// Consider all functions and data structures as experimental.
8+
// !!! WARNING !!! WARNING !!! WARNING !!!
9+
//
10+
// This file contains the C-based API for embedding Node.js in a host
11+
// application. The API is designed to be used by applications that want to
12+
// embed Node.js as a shared library (.so or .dll) and can interop with
13+
// C-based API.
14+
//
15+
16+
#ifndef SRC_NODE_EMBEDDING_API_H_
17+
#define SRC_NODE_EMBEDDING_API_H_
18+
19+
#include "node_api.h"
20+
21+
#define NODE_EMBEDDING_VERSION 1
22+
23+
EXTERN_C_START
24+
25+
// Runs Node.js main function. It is the same as running Node.js from CLI.
26+
NAPI_EXTERN int32_t NAPI_CDECL node_embedding_main(int32_t argc, char* argv[]);
27+
28+
EXTERN_C_END
29+
30+
#endif // SRC_NODE_EMBEDDING_API_H_

0 commit comments

Comments
 (0)