node-ctypes 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
@@ -130,8 +130,8 @@ class CDLL {
130
130
  /**
131
131
  * Ottiene una funzione dalla libreria
132
132
  * @param {string} name - Nome della funzione
133
- * @param {string|CType} returnType - Tipo di ritorno
134
- * @param {Array<string|CType>} argTypes - Tipi degli argomenti
133
+ * @param {Function|number|CType} returnType - Tipo di ritorno (SimpleCData class, CType value, o CType)
134
+ * @param {Array<Function|number|CType>} argTypes - Tipi degli argomenti
135
135
  * @param {Object} [options] - Opzioni aggiuntive (es. { abi: 'stdcall' })
136
136
  * @returns {Function} Funzione callable
137
137
  */
@@ -156,14 +156,7 @@ class CDLL {
156
156
  if (typeof t === "function" && t._isSimpleCData) {
157
157
  // SimpleCData types that are NOT pointers are primitive
158
158
  const typeName = t._type;
159
- return typeName !== "pointer" && typeName !== "char_p" && typeName !== "wchar_p";
160
- }
161
- if (typeof t === "string") {
162
- return t !== "pointer" && t !== "char_p" && t !== "wchar_p" && t !== "void_p";
163
- }
164
- // CType objects from native - check if it's a pointer type
165
- if (t && typeof t === "object" && t.name) {
166
- return !t.name.includes("pointer") && !t.name.includes("char_p");
159
+ return typeName !== native.CType.POINTER && typeName !== native.CType.STRING && typeName !== native.CType.WSTRING;
167
160
  }
168
161
  return false;
169
162
  });
@@ -271,8 +264,8 @@ class CDLL {
271
264
  /**
272
265
  * Crea un callback JS chiamabile da C
273
266
  * @param {Function} fn - Funzione JavaScript
274
- * @param {string|CType} returnType - Tipo di ritorno
275
- * @param {Array<string|CType>} argTypes - Tipi degli argomenti
267
+ * @param {Function|number|CType} returnType - Tipo di ritorno (SimpleCData class, CType value, o CType)
268
+ * @param {Array<Function|number|CType>} argTypes - Tipi degli argomenti
276
269
  * @returns {Object} Oggetto callback con proprietà pointer e metodi
277
270
  */
278
271
  callback(fn, returnType, argTypes = []) {
@@ -87,8 +87,8 @@ import { _toNativeType, _toNativeTypes } from "./types.js";
87
87
  *
88
88
  * @param {Function} fn - JavaScript function to wrap
89
89
  * The function will receive converted arguments based on argTypes
90
- * @param {Function|Object} returnType - Return type (SimpleCData class or CType)
91
- * @param {Array<Function|Object>} argTypes - Argument types array
90
+ * @param {Function|Object|number} returnType - Return type (SimpleCData class, CType, or CType value)
91
+ * @param {Array<Function|Object|number>} argTypes - Argument types array
92
92
  * @param {Object} native - Native module reference (internal use)
93
93
  * @returns {Object} Callback wrapper with properties:
94
94
  * - `pointer` (BigInt): Function pointer to pass to C
@@ -197,8 +197,8 @@ export function callback(fn, returnType, argTypes = [], native) {
197
197
  * @param {Function} fn - JavaScript function to wrap
198
198
  * The function will be executed on Node.js's main thread regardless of
199
199
  * which thread invokes the callback
200
- * @param {Function|Object} returnType - Return type (SimpleCData class or CType)
201
- * @param {Array<Function|Object>} argTypes - Argument types array
200
+ * @param {Function|Object|number} returnType - Return type (SimpleCData class, CType, or CType value)
201
+ * @param {Array<Function|Object|number>} argTypes - Argument types array
202
202
  * @param {Object} native - Native module reference (internal use)
203
203
  * @returns {Object} Callback wrapper with properties:
204
204
  * - `pointer` (BigInt): Function pointer to pass to C
package/lib/core/types.js CHANGED
@@ -11,14 +11,14 @@
11
11
  * @example
12
12
  * ```javascript
13
13
  * import { _toNativeType, _toNativeTypes } from './core/types.js';
14
- * import { c_int32, c_char_p } from './types/integers.js';
14
+ * import { c_int32, c_char_p, CType } from 'node-ctypes';
15
15
  *
16
- * // Convert single type
17
- * const nativeType = _toNativeType(c_int32); // Returns "int32"
16
+ * // Convert single type - returns numeric CType value
17
+ * const nativeType = _toNativeType(c_int32); // Returns CType.INT32 (5)
18
18
  *
19
19
  * // Convert array of types
20
20
  * const nativeTypes = _toNativeTypes([c_int32, c_char_p]);
21
- * // Returns ["int32", <native CType for c_char_p>]
21
+ * // Returns [CType.INT32, CType.STRING]
22
22
  * ```
23
23
  */
24
24
 
@@ -28,34 +28,36 @@
28
28
  *
29
29
  * **Type Conversion Rules**:
30
30
  * 1. **SimpleCData classes** (e.g., `c_int32`, `c_uint64`):
31
- * - Most types Convert to string type name (e.g., `"int32"`, `"uint64"`)
32
- * - `c_char_p` and `c_wchar_p` → Convert to native CType for automatic string marshalling
31
+ * - Returns the numeric CType value (e.g., `CType.INT32`, `CType.STRING`)
33
32
  *
34
33
  * 2. **Structure/Union classes**: Pass through unchanged for struct/union handling
35
34
  *
36
- * 3. **Native CType objects**: Pass through unchanged (already in native format)
35
+ * 3. **Numbers (CType values)**: Pass through unchanged (already in native format)
36
+ *
37
+ * 4. **Native CType objects**: Pass through unchanged (already in native format)
37
38
  *
38
39
  * **Python ctypes Compatibility**:
39
40
  * This function mimics Python's ctypes internal type normalization, ensuring that
40
41
  * type specifications work consistently whether passed as class constructors or
41
42
  * type objects.
42
43
  *
43
- * @param {Function|Object} type - Type specification to normalize
44
+ * @param {Function|Object|number} type - Type specification to normalize
44
45
  * - SimpleCData class (e.g., `c_int32`)
45
46
  * - Structure or Union class
47
+ * - CType numeric value
46
48
  * - Native CType object
47
- * @returns {string|Object} Normalized type for native FFI:
48
- * - String type name for most SimpleCData types
49
- * - Native CType object for string pointer types (c_char_p, c_wchar_p)
49
+ * @param {Object} native - Native module reference (unused but kept for API compatibility)
50
+ * @returns {number|Object} Normalized type for native FFI:
51
+ * - Numeric CType value for SimpleCData types
50
52
  * - Original value for Structure/Union/CType objects
51
53
  *
52
54
  * @example Basic type conversion
53
55
  * ```javascript
54
- * import { c_int32, c_float, c_char_p } from 'node-ctypes';
56
+ * import { c_int32, c_float, c_char_p, CType } from 'node-ctypes';
55
57
  *
56
- * _toNativeType(c_int32); // Returns "int32"
57
- * _toNativeType(c_float); // Returns "float"
58
- * _toNativeType(c_char_p); // Returns native.types.c_char_p (CType object)
58
+ * _toNativeType(c_int32); // Returns CType.INT32 (5)
59
+ * _toNativeType(c_float); // Returns CType.FLOAT (9)
60
+ * _toNativeType(c_char_p); // Returns CType.STRING (12)
59
61
  * ```
60
62
  *
61
63
  * @example Structure type pass-through
@@ -69,18 +71,20 @@
69
71
  * _toNativeType(Point); // Returns Point class unchanged
70
72
  * ```
71
73
  *
74
+ * @example Direct CType usage
75
+ * ```javascript
76
+ * import { CType } from 'node-ctypes';
77
+ *
78
+ * _toNativeType(CType.INT32); // Returns 5 (pass-through)
79
+ * ```
80
+ *
72
81
  * @private
73
82
  * @internal
74
83
  */
75
84
  export function _toNativeType(type, native) {
76
- // SimpleCData classes: convert to string type names or native CTypes
85
+ // SimpleCData classes: return the numeric CType value directly
77
86
  if (typeof type === "function" && type._isSimpleCData) {
78
- // String pointer types need native CType for automatic conversion
79
- // This enables automatic marshalling between C strings and JS strings
80
- if (type._type === "char_p") return native.types.c_char_p;
81
- if (type._type === "wchar_p") return native.types.c_wchar_p;
82
-
83
- // All other SimpleCData types: use string type name
87
+ // _type is now a numeric CType value from native.CType
84
88
  return type._type;
85
89
  }
86
90
 
@@ -92,6 +96,11 @@ export function _toNativeType(type, native) {
92
96
  return type;
93
97
  }
94
98
 
99
+ // Numbers (direct CType values): pass through unchanged
100
+ if (typeof type === "number") {
101
+ return type;
102
+ }
103
+
95
104
  // Native CType objects: pass through unchanged (already in correct format)
96
105
  return type;
97
106
  }
@@ -108,16 +117,16 @@ export function _toNativeType(type, native) {
108
117
  *
109
118
  * @param {Array|*} types - Array of type specifications, or non-array value
110
119
  * @param {Object} native - Native module reference for CType lookups
111
- * @returns {Array|*} Array of normalized types, or original value if not an array
120
+ * @returns {Array|*} Array of normalized types (CType values), or original value if not an array
112
121
  *
113
122
  * @example Function signature normalization
114
123
  * ```javascript
115
- * import { c_int32, c_char_p, c_void_p } from 'node-ctypes';
124
+ * import { c_int32, c_char_p, c_void_p, CType } from 'node-ctypes';
116
125
  *
117
126
  * // Normalize function argument types
118
127
  * const argTypes = [c_int32, c_char_p, c_void_p];
119
128
  * const normalized = _toNativeTypes(argTypes);
120
- * // Returns ["int32", <native c_char_p CType>, "void_p"]
129
+ * // Returns [CType.INT32, CType.STRING, CType.POINTER]
121
130
  * ```
122
131
  *
123
132
  * @example Non-array pass-through
package/lib/index.d.ts CHANGED
@@ -9,14 +9,42 @@
9
9
  // Basic Types
10
10
  // =============================================================================
11
11
 
12
- /** Native CType object (internal C++ type representation) */
13
- export interface CType {
14
- readonly size: number;
15
- readonly name: string;
12
+ /**
13
+ * CType - Object containing numeric type identifiers
14
+ * Single source of truth for type values
15
+ */
16
+ export interface CTypeValues {
17
+ readonly VOID: number;
18
+ readonly INT8: number;
19
+ readonly UINT8: number;
20
+ readonly INT16: number;
21
+ readonly UINT16: number;
22
+ readonly INT32: number;
23
+ readonly UINT32: number;
24
+ readonly INT64: number;
25
+ readonly UINT64: number;
26
+ readonly FLOAT: number;
27
+ readonly DOUBLE: number;
28
+ readonly POINTER: number;
29
+ readonly STRING: number;
30
+ readonly WSTRING: number;
31
+ readonly WCHAR: number;
32
+ readonly BOOL: number;
33
+ readonly SIZE_T: number;
34
+ readonly SSIZE_T: number;
35
+ readonly LONG: number;
36
+ readonly ULONG: number;
37
+ readonly STRUCT: number;
38
+ readonly UNION: number;
39
+ readonly ARRAY: number;
40
+ readonly COUNT: number;
16
41
  }
17
42
 
18
- /** Any accepted type specification (CType object or SimpleCData class) */
19
- export type AnyType = CType | SimpleCDataConstructor;
43
+ /** CType object with numeric type identifiers */
44
+ export const CType: CTypeValues;
45
+
46
+ /** Any accepted type specification (SimpleCData class, CType value, or struct/union) */
47
+ export type AnyType = SimpleCDataConstructor | number | StructDef | UnionDef;
20
48
 
21
49
  // =============================================================================
22
50
  // Library & Function
@@ -315,7 +343,7 @@ export function WinError(code?: number): Error & { winerror: number };
315
343
  export interface SimpleCDataConstructor {
316
344
  new (value?: any): SimpleCDataInstance;
317
345
  readonly _size: number;
318
- readonly _type: string;
346
+ readonly _type: number; // CType numeric value from native module
319
347
  readonly _isSimpleCData: true;
320
348
  _reader(buf: Buffer, offset: number): any;
321
349
  _writer(buf: Buffer, offset: number, value: any): void;
package/lib/index.js CHANGED
@@ -140,7 +140,7 @@ const native = require(nativeModulePath);
140
140
  _initConstants(native);
141
141
 
142
142
  // Re-esporta le classi native
143
- const { Version, Library, FFIFunction, Callback, ThreadSafeCallback, CType, StructType, ArrayType } = native;
143
+ const { Version, Library, FFIFunction, Callback, ThreadSafeCallback, StructType, ArrayType, CType } = native;
144
144
 
145
145
  // ============================================================================
146
146
  // Type Normalization Helpers
@@ -56,8 +56,7 @@ export function addressOf(ptr, alloc, native) {
56
56
  if (Buffer.isBuffer(ptr)) {
57
57
  // Get the buffer's memory address
58
58
  const tempBuf = alloc(native.POINTER_SIZE);
59
- // Use native.writeValue with string 'pointer' to avoid JS-level recursion
60
- native.writeValue(tempBuf, "pointer", ptr, 0);
59
+ native.writeValue(tempBuf, native.CType.POINTER, ptr, 0);
61
60
  if (native.POINTER_SIZE === 8) return tempBuf.readBigUInt64LE(0);
62
61
  return BigInt(tempBuf.readUInt32LE(0));
63
62
  }
@@ -13,11 +13,11 @@
13
13
  *
14
14
  * @example Creating custom type
15
15
  * ```javascript
16
- * import { SimpleCData } from 'node-ctypes';
16
+ * import { SimpleCData, CType } from 'node-ctypes';
17
17
  *
18
18
  * class c_int32 extends SimpleCData {
19
19
  * static _size = 4;
20
- * static _type = 'int32';
20
+ * static _type = CType.INT32; // Numeric enum value from native module
21
21
  * static _reader = (buf, off) => buf.readInt32LE(off);
22
22
  * static _writer = (buf, off, val) => buf.writeInt32LE(val, off);
23
23
  * }
@@ -59,7 +59,7 @@ export function createSimpleCDataClass(alloc) {
59
59
  *
60
60
  * Subclasses must define:
61
61
  * - `static _size`: Size in bytes
62
- * - `static _type`: Type name string
62
+ * - `static _type`: CType numeric value (from native.CType)
63
63
  * - `static _reader(buffer, offset)`: Function to read value from buffer
64
64
  * - `static _writer(buffer, offset, value)`: Function to write value to buffer
65
65
  *
@@ -76,7 +76,7 @@ export function createSimpleCDataClass(alloc) {
76
76
  * ```javascript
77
77
  * class c_uint8 extends SimpleCData {
78
78
  * static _size = 1;
79
- * static _type = 'uint8';
79
+ * static _type = CType.UINT8; // Numeric enum from native module
80
80
  * static _reader = (buf, off) => buf.readUInt8(off);
81
81
  * static _writer = (buf, off, val) => buf.writeUInt8(val, off);
82
82
  * }
@@ -91,7 +91,7 @@ export function createSimpleCDataClass(alloc) {
91
91
  * ```javascript
92
92
  * class c_float extends SimpleCData {
93
93
  * static _size = 4;
94
- * static _type = 'float';
94
+ * static _type = CType.FLOAT;
95
95
  * static _reader = (buf, off) => buf.readFloatLE(off);
96
96
  * static _writer = (buf, off, val) => buf.writeFloatLE(val, off);
97
97
  * }
@@ -4,7 +4,12 @@
4
4
  * @description Primitive C type definitions (integers, floats, chars, pointers).
5
5
  *
6
6
  * This module provides all primitive C types that extend SimpleCData. Each type
7
- * defines its size, type name, and read/write functions for buffer operations.
7
+ * defines its size, CType value, and read/write functions for buffer operations.
8
+ *
9
+ * **Type System**:
10
+ * All types use numeric CType values from the native module as their `_type`
11
+ * property. This enables efficient type passing to the native FFI layer without
12
+ * string lookups.
8
13
  *
9
14
  * **Python ctypes Compatibility**:
10
15
  * All types are compatible with Python's ctypes module equivalents.
@@ -58,8 +63,14 @@
58
63
  /**
59
64
  * Creates all primitive type classes with required dependencies injected.
60
65
  *
66
+ * Each type class has:
67
+ * - `_size`: Size in bytes
68
+ * - `_type`: CType numeric value (from native.CType)
69
+ * - `_reader`: Function to read value from buffer
70
+ * - `_writer`: Function to write value to buffer
71
+ *
61
72
  * @param {Class} SimpleCData - SimpleCData base class
62
- * @param {Object} native - Native module with POINTER_SIZE
73
+ * @param {Object} native - Native module with POINTER_SIZE and CType
63
74
  * @param {Function} addressOf - addressOf function for pointers
64
75
  * @param {Function} cstring - cstring function for c_char_p
65
76
  * @param {Function} wstring - wstring function for c_wchar_p
@@ -69,13 +80,16 @@
69
80
  * @private
70
81
  */
71
82
  export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, wstring, readCString, readWString) {
83
+ // Get CType from native module - single source of truth
84
+ const CType = native.CType;
85
+
72
86
  // ============================================================================
73
87
  // Void type
74
88
  // ============================================================================
75
89
 
76
90
  class c_void extends SimpleCData {
77
91
  static _size = 0;
78
- static _type = "void";
92
+ static _type = CType.VOID;
79
93
  static _reader = (buf, off) => undefined;
80
94
  static _writer = (buf, off, val) => {};
81
95
  }
@@ -86,21 +100,21 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
86
100
 
87
101
  class c_int8 extends SimpleCData {
88
102
  static _size = 1;
89
- static _type = "int8";
103
+ static _type = CType.INT8;
90
104
  static _reader = (buf, off) => buf.readInt8(off);
91
105
  static _writer = (buf, off, val) => buf.writeInt8(val, off);
92
106
  }
93
107
 
94
108
  class c_int16 extends SimpleCData {
95
109
  static _size = 2;
96
- static _type = "int16";
110
+ static _type = CType.INT16;
97
111
  static _reader = (buf, off) => buf.readInt16LE(off);
98
112
  static _writer = (buf, off, val) => buf.writeInt16LE(val, off);
99
113
  }
100
114
 
101
115
  class c_int32 extends SimpleCData {
102
116
  static _size = 4;
103
- static _type = "int32";
117
+ static _type = CType.INT32;
104
118
  static _reader = (buf, off) => buf.readInt32LE(off);
105
119
  static _writer = (buf, off, val) => {
106
120
  const v = Number(val) | 0; // coerce to signed 32-bit
@@ -110,7 +124,7 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
110
124
 
111
125
  class c_int64 extends SimpleCData {
112
126
  static _size = 8;
113
- static _type = "int64";
127
+ static _type = CType.INT64;
114
128
  static _reader = (buf, off) => buf.readBigInt64LE(off);
115
129
  static _writer = (buf, off, val) => buf.writeBigInt64LE(BigInt(val), off);
116
130
  }
@@ -121,21 +135,21 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
121
135
 
122
136
  class c_uint8 extends SimpleCData {
123
137
  static _size = 1;
124
- static _type = "uint8";
138
+ static _type = CType.UINT8;
125
139
  static _reader = (buf, off) => buf.readUInt8(off);
126
140
  static _writer = (buf, off, val) => buf.writeUInt8(val, off);
127
141
  }
128
142
 
129
143
  class c_uint16 extends SimpleCData {
130
144
  static _size = 2;
131
- static _type = "uint16";
145
+ static _type = CType.UINT16;
132
146
  static _reader = (buf, off) => buf.readUInt16LE(off);
133
147
  static _writer = (buf, off, val) => buf.writeUInt16LE(val, off);
134
148
  }
135
149
 
136
150
  class c_uint32 extends SimpleCData {
137
151
  static _size = 4;
138
- static _type = "uint32";
152
+ static _type = CType.UINT32;
139
153
  static _reader = (buf, off) => buf.readUInt32LE(off);
140
154
  static _writer = (buf, off, val) => {
141
155
  const v = Number(val) >>> 0; // coerce to unsigned 32-bit
@@ -145,7 +159,7 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
145
159
 
146
160
  class c_uint64 extends SimpleCData {
147
161
  static _size = 8;
148
- static _type = "uint64";
162
+ static _type = CType.UINT64;
149
163
  static _reader = (buf, off) => buf.readBigUInt64LE(off);
150
164
  static _writer = (buf, off, val) => buf.writeBigUInt64LE(BigInt(val), off);
151
165
  }
@@ -156,14 +170,14 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
156
170
 
157
171
  class c_float extends SimpleCData {
158
172
  static _size = 4;
159
- static _type = "float";
173
+ static _type = CType.FLOAT;
160
174
  static _reader = (buf, off) => buf.readFloatLE(off);
161
175
  static _writer = (buf, off, val) => buf.writeFloatLE(val, off);
162
176
  }
163
177
 
164
178
  class c_double extends SimpleCData {
165
179
  static _size = 8;
166
- static _type = "double";
180
+ static _type = CType.DOUBLE;
167
181
  static _reader = (buf, off) => buf.readDoubleLE(off);
168
182
  static _writer = (buf, off, val) => buf.writeDoubleLE(val, off);
169
183
  }
@@ -174,7 +188,7 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
174
188
 
175
189
  class c_bool extends SimpleCData {
176
190
  static _size = 1;
177
- static _type = "bool";
191
+ static _type = CType.BOOL;
178
192
  static _reader = (buf, off) => buf.readUInt8(off) !== 0;
179
193
  static _writer = (buf, off, val) => buf.writeUInt8(val ? 1 : 0, off);
180
194
  }
@@ -185,7 +199,7 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
185
199
 
186
200
  class c_char extends SimpleCData {
187
201
  static _size = 1;
188
- static _type = "char";
202
+ static _type = CType.INT8; // char is int8 in C
189
203
  static _reader = (buf, off) => buf.readInt8(off);
190
204
  static _writer = (buf, off, val) => {
191
205
  if (typeof val === "string") val = val.charCodeAt(0);
@@ -195,7 +209,7 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
195
209
 
196
210
  class c_wchar extends SimpleCData {
197
211
  static _size = native.WCHAR_SIZE;
198
- static _type = "wchar";
212
+ static _type = CType.WCHAR;
199
213
  static _reader = (buf, off) => {
200
214
  if (native.WCHAR_SIZE === 2) {
201
215
  return String.fromCharCode(buf.readUInt16LE(off));
@@ -218,7 +232,7 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
218
232
 
219
233
  class c_void_p extends SimpleCData {
220
234
  static _size = native.POINTER_SIZE;
221
- static _type = "pointer";
235
+ static _type = CType.POINTER;
222
236
  static _reader = (buf, off) => {
223
237
  const ptr = native.POINTER_SIZE === 8 ? buf.readBigUInt64LE(off) : BigInt(buf.readUInt32LE(off));
224
238
  if (!ptr) return null;
@@ -257,7 +271,7 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
257
271
 
258
272
  class c_size_t extends SimpleCData {
259
273
  static _size = native.POINTER_SIZE;
260
- static _type = "size_t";
274
+ static _type = CType.SIZE_T;
261
275
  static _reader = (buf, off) => {
262
276
  return native.POINTER_SIZE === 8 ? buf.readBigUInt64LE(off) : buf.readUInt32LE(off);
263
277
  };
@@ -271,18 +285,18 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
271
285
  }
272
286
 
273
287
  // Get actual long size from native module (4 on Windows, 4 or 8 on Unix depending on arch)
274
- const _longSize = native.sizeof ? native.sizeof("long") : 4;
288
+ const _longSize = native.sizeof ? native.sizeof(CType.LONG) : 4;
275
289
 
276
290
  class c_long extends SimpleCData {
277
291
  static _size = _longSize;
278
- static _type = "long";
292
+ static _type = CType.LONG;
279
293
  static _reader = _longSize === 8 ? (buf, off) => buf.readBigInt64LE(off) : (buf, off) => buf.readInt32LE(off);
280
294
  static _writer = _longSize === 8 ? (buf, off, val) => buf.writeBigInt64LE(BigInt(val), off) : (buf, off, val) => buf.writeInt32LE(val, off);
281
295
  }
282
296
 
283
297
  class c_ulong extends SimpleCData {
284
298
  static _size = _longSize;
285
- static _type = "ulong";
299
+ static _type = CType.ULONG;
286
300
  static _reader = _longSize === 8 ? (buf, off) => buf.readBigUInt64LE(off) : (buf, off) => buf.readUInt32LE(off);
287
301
  static _writer = _longSize === 8 ? (buf, off, val) => buf.writeBigUInt64LE(BigInt(val), off) : (buf, off, val) => buf.writeUInt32LE(val, off);
288
302
  }
@@ -293,7 +307,7 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
293
307
 
294
308
  class c_char_p extends SimpleCData {
295
309
  static _size = native.POINTER_SIZE;
296
- static _type = "char_p";
310
+ static _type = CType.STRING;
297
311
  static _reader = (buf, off) => {
298
312
  const ptr = native.POINTER_SIZE === 8 ? buf.readBigUInt64LE(off) : BigInt(buf.readUInt32LE(off));
299
313
  if (!ptr) return null;
@@ -324,7 +338,7 @@ export function createPrimitiveTypes(SimpleCData, native, addressOf, cstring, ws
324
338
 
325
339
  class c_wchar_p extends SimpleCData {
326
340
  static _size = native.POINTER_SIZE;
327
- static _type = "wchar_p";
341
+ static _type = CType.WSTRING;
328
342
  static _reader = (buf, off) => {
329
343
  const ptr = native.POINTER_SIZE === 8 ? buf.readBigUInt64LE(off) : BigInt(buf.readUInt32LE(off));
330
344
  if (!ptr) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-ctypes",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Python ctypes-like FFI for Node.js using libffi",
5
5
  "author": "Damiano Mazzella",
6
6
  "license": "MIT",
@@ -32,7 +32,7 @@
32
32
  "generate-ffi-headers": "node third-party/libffi_cmake/generate-headers.js"
33
33
  },
34
34
  "devDependencies": {
35
- "cmake-js": "^7.4.0",
35
+ "cmake-js": "^8.0.0",
36
36
  "node-addon-api": "^8.5.0"
37
37
  },
38
38
  "engines": {