Repository navigation
Expand file tree
/
Copy pathpythonodejs.h
More file actions
136 lines (117 loc) · 3.8 KB
/
Copy pathpythonodejs.h
File metadata and controls
136 lines (117 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef NODE_EMBED_H
#define NODE_EMBED_H
#ifdef _WIN32
#define EXPORT __declspec(dllexport)
#define NOMINMAX
#else
#define EXPORT
#endif
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __cplusplus
typedef enum { false, true } bool;
#endif
typedef struct NodeContext NodeContext;
typedef struct Func Func;
typedef struct Val Val;
typedef enum NodeValueType : int { // explicitly 4 bytes
UNDEFINED,
NULL_T,
BOOLEAN_T,
NUMBER,
STRING,
SYMBOL,
FUNCTION,
ARRAY,
BIGINT,
OBJECT,
UNKNOWN,
MAP,
TYPED_ARRAY,
ARRAY_BUFFER,
DATA_VIEW, // UNUSED (ARRAY_BUFFER)
EXTERNAL,
DATE_T,
REGEXP,
PROXY,
GENERATOR_OBJECT, // UNUSED (Object)
MODULE_NAMESPACE, // UNUSED (Object)
ERROR_T,
PROMISE,
SET
} NodeValueType;
typedef enum TypedArrayType : int { // explicitly 4 bytes
INT8_T,
UINT8_T,
INT16_T,
UINT16_T,
INT32_T,
UINT32_T,
BINT64_T,
BUINT64_T,
FLOAT32_T,
FLOAT64_T
} TypedArrayType;
typedef struct NodeValue {
NodeValueType type;
void *self_ptr;
bool val_bool;
double val_num;
char *val_string; // Used for string, symbol description, function name, and
// regex pattern
struct Func *function;
struct NodeValue *val_array; // Reuse for set
void *val_tarray; // Reuse for arraybuffer and dataview
TypedArrayType val_tarray_type;
int val_array_len; // Reuse for set, typedarray and arraybuffer
char *val_big;
char **object_keys;
struct NodeValue *map_keys;
struct NodeValue *object_values; // Reuse for map
int object_len;
double val_date_unix;
int val_regex_flags;
void *val_external_ptr; // Reuse for Symbol
int64_t future_id;
char *error_message;
char *error_name;
char *error_stack;
struct NodeValue *proxy_target;
struct NodeValue *proxy_handler;
void *parent;
} NodeValue;
typedef void *(*Callback)(const char *function_name, const NodeValue *values,
int length);
typedef void *(*FutureCallback)(int64_t id, NodeValue result, bool reject);
EXPORT NodeContext *NodeContext_Create();
EXPORT int NodeContext_Setup(NodeContext *context, int argc, char **argv);
EXPORT int NodeContext_Init(NodeContext *context, char **imports,
int num_imports, int thread_pool_size);
EXPORT void NodeContext_SetCallback(NodeContext *context, Callback cb);
EXPORT void NodeContext_SetFutureCallback(NodeContext *context,
FutureCallback cb);
EXPORT void NodeContext_Define_Global(NodeContext *context, const char **keys,
NodeValue *values, int length);
EXPORT void NodeContext_FutureUpdate(NodeContext *context, int64_t id,
NodeValue value, bool rejected);
EXPORT NodeValue NodeContext_Run_Script(NodeContext *context, const char *code);
EXPORT NodeValue NodeContext_Create_Function(NodeContext *context,
const char *function_name);
EXPORT NodeValue NodeContext_Call_Function(NodeContext *context,
NodeValue function, NodeValue *args,
size_t args_length);
EXPORT NodeValue NodeContext_Construct_Function(NodeContext *context,
NodeValue function,
NodeValue *args,
size_t args_length);
EXPORT void NodeContext_Stop(NodeContext *context);
EXPORT void NodeContext_Destroy(NodeContext *context);
EXPORT void NodeContext_Dispose(NodeContext *context);
EXPORT void Node_Dispose_Value(NodeValue value);
#ifdef __cplusplus
}
#endif
#endif // NODE_EMBED_H