File tree Expand file tree Collapse file tree 2 files changed +77
-0
lines changed
lib/node_modules/@stdlib/napi/export Expand file tree Collapse file tree 2 files changed +77
-0
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,37 @@ The macro expects the following arguments:
129
129
130
130
When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
131
131
132
+ #### STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( fcn_name, prop_name, method_name )
133
+
134
+ Macro for registering a Node-API module which exports a function having a method.
135
+
136
+ ```c
137
+ #include <node_api.h>
138
+
139
+ // ...
140
+
141
+ static napi_value addon( napi_env env, napi_callback_info info ) {
142
+ // ...
143
+ }
144
+
145
+ static napi_value method( napi_env env, napi_callback_info info ) {
146
+ // ...
147
+ }
148
+
149
+ // ...
150
+
151
+ // Register a Node-API module:
152
+ STDLIB_NAPI_MODULE_EXPORT_FCN( addon, "foo", method )
153
+ ```
154
+
155
+ The macro expects the following arguments:
156
+
157
+ - ** fcn_name** : name of the C function to export.
158
+ - ** prop_name** : property name.
159
+ - ** method_name** : name of the C function to export as a method.
160
+
161
+ When used, this macro should be used ** instead of** ` NAPI_MODULE ` . The macro includes ` NAPI_MODULE ` , thus ensuring Node-API module registration.
162
+
132
163
</section >
133
164
134
165
<!-- /.usage -->
Original file line number Diff line number Diff line change 60
60
}; \
61
61
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_napi_module_export_fcn_init )
62
62
63
+ /**
64
+ * Macro for registering a Node-API module which exports a function having a method.
65
+ *
66
+ * @param fcn_name exported function name
67
+ * @param prop_name property name
68
+ * @param method_name exported function name for the method
69
+ *
70
+ * @example
71
+ * #include <node_api.h>
72
+ *
73
+ * // ...
74
+ *
75
+ * static napi_value addon( napi_env env, napi_callback_info info ) {
76
+ * // ...
77
+ * }
78
+ *
79
+ * static napi_value method( napi_env env, napi_callback_info info ) {
80
+ * // ...
81
+ * }
82
+ *
83
+ * // ...
84
+ *
85
+ * // Register a Node-API module:
86
+ * STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "foo", method )
87
+ */
88
+ #define STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD ( fcn_name , prop_name , method_name ) \
89
+ static napi_value stdlib_napi_module_export_fcn_with_method_init( \
90
+ napi_env env, \
91
+ napi_value exports \
92
+ ) { \
93
+ napi_value fcn; \
94
+ napi_status status = napi_create_function( \
95
+ env, \
96
+ "exports", \
97
+ NAPI_AUTO_LENGTH, \
98
+ fcn_name, \
99
+ NULL, \
100
+ &fcn \
101
+ ); \
102
+ assert( status == napi_ok ); \
103
+ status = napi_set_named_property( env, fcn, prop_name, method_name ) \
104
+ assert( status == napi_ok ); \
105
+ return fcn; \
106
+ }; \
107
+ NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_napi_module_export_fcn_with_method_init )
108
+
63
109
#endif // !STDLIB_NAPI_EXPORT_H
You can’t perform that action at this time.
0 commit comments