koffi 3.0.1 → 3.1.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.
- package/CHANGELOG.md +32 -3
- package/cnoke.cjs +2 -2
- package/doc/benchmarks.md +1 -1
- package/doc/callbacks.md +7 -26
- package/doc/{input.md → composites.md} +161 -147
- package/doc/contribute.md +3 -2
- package/doc/index.md +0 -14
- package/doc/{functions.md → load.md} +54 -113
- package/doc/migration.md +4 -7
- package/doc/misc.md +0 -103
- package/doc/output.md +5 -11
- package/doc/pointers.md +76 -17
- package/doc/primitives.md +151 -0
- package/doc/start.md +3 -13
- package/doc/types.md +88 -0
- package/doc/unions.md +0 -186
- package/doc/values.md +134 -0
- package/index.d.ts +375 -308
- package/lib/native/base/base.cc +66 -24
- package/lib/native/base/base.hh +55 -153
- package/package.json +16 -16
- package/src/koffi/CMakeLists.txt +20 -17
- package/src/koffi/index.cjs +30 -111
- package/src/koffi/index.js +22 -96
- package/src/koffi/indirect.cjs +30 -111
- package/src/koffi/indirect.js +24 -24
- package/src/koffi/src/abi/arm64.cc +48 -62
- package/src/koffi/src/abi/riscv64.cc +39 -57
- package/src/koffi/src/abi/x64sysv.cc +39 -57
- package/src/koffi/src/abi/x64win.cc +48 -65
- package/src/koffi/src/abi/x86.cc +47 -59
- package/src/koffi/src/call.cc +426 -209
- package/src/koffi/src/call.hh +7 -11
- package/src/koffi/src/ffi.cc +534 -303
- package/src/koffi/src/ffi.hh +71 -15
- package/src/koffi/src/parser.cc +5 -3
- package/src/koffi/src/parser.hh +2 -2
- package/src/koffi/src/static.cjs +122 -0
- package/src/koffi/src/static.js +125 -0
- package/src/koffi/src/type.cc +725 -0
- package/src/koffi/src/type.hh +71 -0
- package/src/koffi/src/util.cc +117 -1202
- package/src/koffi/src/util.hh +158 -156
- package/src/koffi/src/uv.cc +17 -11
- package/src/koffi/src/uv.hh +2 -1
- package/vendor/node-addon-api/README.md +1 -1
- package/vendor/node-addon-api/napi-inl.h +213 -35
- package/vendor/node-addon-api/napi.h +118 -7
- package/doc/variables.md +0 -102
- package/indirect.d.ts +0 -322
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
#if NAPI_HAS_THREADS
|
|
18
18
|
#include <mutex>
|
|
19
19
|
#endif // NAPI_HAS_THREADS
|
|
20
|
+
#include <chrono>
|
|
20
21
|
#include <string>
|
|
22
|
+
#include <string_view>
|
|
21
23
|
#include <vector>
|
|
22
24
|
|
|
23
25
|
// VS2015 RTM has bugs with constexpr, so require min of VS2015 Update 3 (known
|
|
@@ -359,10 +361,10 @@ class BasicEnv {
|
|
|
359
361
|
// ... occurs when comparing foo.Env() == bar.Env() or foo.Env() == nullptr
|
|
360
362
|
bool operator==(const BasicEnv& other) const {
|
|
361
363
|
return _env == other._env;
|
|
362
|
-
}
|
|
364
|
+
}
|
|
363
365
|
bool operator==(std::nullptr_t /*other*/) const {
|
|
364
366
|
return _env == nullptr;
|
|
365
|
-
}
|
|
367
|
+
}
|
|
366
368
|
|
|
367
369
|
#if NAPI_VERSION > 2
|
|
368
370
|
template <typename Hook, typename Arg = void>
|
|
@@ -543,6 +545,9 @@ class Value {
|
|
|
543
545
|
bool IsDataView() const; ///< Tests if a value is a JavaScript data view.
|
|
544
546
|
bool IsBuffer() const; ///< Tests if a value is a Node buffer.
|
|
545
547
|
bool IsExternal() const; ///< Tests if a value is a pointer to external data.
|
|
548
|
+
#ifdef NODE_API_EXPERIMENTAL_HAS_SHAREDARRAYBUFFER
|
|
549
|
+
bool IsSharedArrayBuffer() const;
|
|
550
|
+
#endif
|
|
546
551
|
|
|
547
552
|
/// Casts to another type of `Napi::Value`, when the actual type is known or
|
|
548
553
|
/// assumed.
|
|
@@ -682,6 +687,12 @@ class Date : public Value {
|
|
|
682
687
|
double value ///< Number value
|
|
683
688
|
);
|
|
684
689
|
|
|
690
|
+
/// Creates a new Date value from a std::chrono::system_clock::time_point.
|
|
691
|
+
static Date New(
|
|
692
|
+
napi_env env, ///< Node-API environment
|
|
693
|
+
std::chrono::system_clock::time_point time_point ///< Time point value
|
|
694
|
+
);
|
|
695
|
+
|
|
685
696
|
static void CheckCast(napi_env env, napi_value value);
|
|
686
697
|
|
|
687
698
|
Date(); ///< Creates a new _empty_ Date instance.
|
|
@@ -715,6 +726,11 @@ class String : public Name {
|
|
|
715
726
|
const std::u16string& value ///< UTF-16 encoded C++ string
|
|
716
727
|
);
|
|
717
728
|
|
|
729
|
+
/// Creates a new String value from a UTF-8 encoded C++ string view.
|
|
730
|
+
static String New(napi_env env, ///< Node-API environment
|
|
731
|
+
std::string_view value ///< UTF-8 encoded C++ string view
|
|
732
|
+
);
|
|
733
|
+
|
|
718
734
|
/// Creates a new String value from a UTF-8 encoded C string.
|
|
719
735
|
static String New(
|
|
720
736
|
napi_env env, ///< Node-API environment
|
|
@@ -788,6 +804,13 @@ class Symbol : public Name {
|
|
|
788
804
|
description ///< UTF-8 encoded C++ string describing the symbol
|
|
789
805
|
);
|
|
790
806
|
|
|
807
|
+
/// Creates a new Symbol value with a description.
|
|
808
|
+
static Symbol New(
|
|
809
|
+
napi_env env, ///< Node-API environment
|
|
810
|
+
std::string_view
|
|
811
|
+
description ///< UTF-8 encoded C++ string view describing the symbol
|
|
812
|
+
);
|
|
813
|
+
|
|
791
814
|
/// Creates a new Symbol value with a description.
|
|
792
815
|
static Symbol New(napi_env env, ///< Node-API environment
|
|
793
816
|
String description ///< String value describing the symbol
|
|
@@ -805,6 +828,9 @@ class Symbol : public Name {
|
|
|
805
828
|
// Create a symbol in the global registry, UTF-8 Encoded cpp string
|
|
806
829
|
static MaybeOrValue<Symbol> For(napi_env env, const std::string& description);
|
|
807
830
|
|
|
831
|
+
// Create a symbol in the global registry, UTF-8 encoded cpp string view
|
|
832
|
+
static MaybeOrValue<Symbol> For(napi_env env, std::string_view description);
|
|
833
|
+
|
|
808
834
|
// Create a symbol in the global registry, C style string (null terminated)
|
|
809
835
|
static MaybeOrValue<Symbol> For(napi_env env, const char* description);
|
|
810
836
|
|
|
@@ -1115,6 +1141,12 @@ class Object : public TypeTaggable {
|
|
|
1115
1141
|
/// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-getprototypeof
|
|
1116
1142
|
MaybeOrValue<bool> Seal() const;
|
|
1117
1143
|
#endif // NAPI_VERSION >= 8
|
|
1144
|
+
|
|
1145
|
+
MaybeOrValue<Object> GetPrototype() const;
|
|
1146
|
+
|
|
1147
|
+
#ifdef NODE_API_EXPERIMENTAL_HAS_SET_PROTOTYPE
|
|
1148
|
+
MaybeOrValue<bool> SetPrototype(const Object& value) const;
|
|
1149
|
+
#endif
|
|
1118
1150
|
};
|
|
1119
1151
|
|
|
1120
1152
|
template <typename T>
|
|
@@ -1202,6 +1234,21 @@ class Object::iterator {
|
|
|
1202
1234
|
};
|
|
1203
1235
|
#endif // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
1204
1236
|
|
|
1237
|
+
#ifdef NODE_API_EXPERIMENTAL_HAS_SHAREDARRAYBUFFER
|
|
1238
|
+
class SharedArrayBuffer : public Object {
|
|
1239
|
+
public:
|
|
1240
|
+
SharedArrayBuffer();
|
|
1241
|
+
SharedArrayBuffer(napi_env env, napi_value value);
|
|
1242
|
+
|
|
1243
|
+
static SharedArrayBuffer New(napi_env env, size_t byteLength);
|
|
1244
|
+
|
|
1245
|
+
static void CheckCast(napi_env env, napi_value value);
|
|
1246
|
+
|
|
1247
|
+
void* Data();
|
|
1248
|
+
size_t ByteLength();
|
|
1249
|
+
};
|
|
1250
|
+
#endif
|
|
1251
|
+
|
|
1205
1252
|
/// A JavaScript array buffer value.
|
|
1206
1253
|
class ArrayBuffer : public Object {
|
|
1207
1254
|
public:
|
|
@@ -1292,7 +1339,21 @@ class TypedArray : public Object {
|
|
|
1292
1339
|
|
|
1293
1340
|
napi_typedarray_type TypedArrayType()
|
|
1294
1341
|
const; ///< Gets the type of this typed-array.
|
|
1295
|
-
|
|
1342
|
+
|
|
1343
|
+
// Gets the backing `ArrayBuffer`.
|
|
1344
|
+
//
|
|
1345
|
+
// If this `TypedArray` is not backed by an `ArrayBuffer`, this method will
|
|
1346
|
+
// terminate the process with a fatal error when using
|
|
1347
|
+
// `NODE_ADDON_API_ENABLE_TYPE_CHECK_ON_AS` or exhibit undefined behavior
|
|
1348
|
+
// otherwise. Use `Buffer()` instead to get the backing buffer without
|
|
1349
|
+
// assuming its type.
|
|
1350
|
+
Napi::ArrayBuffer ArrayBuffer() const;
|
|
1351
|
+
|
|
1352
|
+
// Gets the backing buffer (an `ArrayBuffer` or `SharedArrayBuffer`).
|
|
1353
|
+
//
|
|
1354
|
+
// Use `IsArrayBuffer()` or `IsSharedArrayBuffer()` to check the type of the
|
|
1355
|
+
// backing buffer prior to casting with `As<T>()`.
|
|
1356
|
+
Napi::Value Buffer() const;
|
|
1296
1357
|
|
|
1297
1358
|
uint8_t ElementSize()
|
|
1298
1359
|
const; ///< Gets the size in bytes of one element in the array.
|
|
@@ -1386,6 +1447,32 @@ class TypedArrayOf : public TypedArray {
|
|
|
1386
1447
|
///< template parameter T.
|
|
1387
1448
|
);
|
|
1388
1449
|
|
|
1450
|
+
#ifdef NODE_API_EXPERIMENTAL_HAS_SHAREDARRAYBUFFER
|
|
1451
|
+
/// Creates a new TypedArray instance over a provided SharedArrayBuffer.
|
|
1452
|
+
///
|
|
1453
|
+
/// The array type parameter can normally be omitted (because it is inferred
|
|
1454
|
+
/// from the template parameter T), except when creating a "clamped" array:
|
|
1455
|
+
///
|
|
1456
|
+
/// Uint8Array::New(env, length, buffer, 0, napi_uint8_clamped_array)
|
|
1457
|
+
static TypedArrayOf New(
|
|
1458
|
+
napi_env env, ///< Node-API environment
|
|
1459
|
+
size_t elementLength, ///< Length of the created array, as a number of
|
|
1460
|
+
///< elements
|
|
1461
|
+
Napi::SharedArrayBuffer
|
|
1462
|
+
arrayBuffer, ///< Backing shared array buffer instance to use
|
|
1463
|
+
size_t bufferOffset, ///< Offset into the array buffer where the
|
|
1464
|
+
///< typed-array starts
|
|
1465
|
+
#if defined(NAPI_HAS_CONSTEXPR)
|
|
1466
|
+
napi_typedarray_type type =
|
|
1467
|
+
TypedArray::TypedArrayTypeForPrimitiveType<T>()
|
|
1468
|
+
#else
|
|
1469
|
+
napi_typedarray_type type
|
|
1470
|
+
#endif
|
|
1471
|
+
///< Type of array, if different from the default array type for the
|
|
1472
|
+
///< template parameter T.
|
|
1473
|
+
);
|
|
1474
|
+
#endif
|
|
1475
|
+
|
|
1389
1476
|
static void CheckCast(napi_env env, napi_value value);
|
|
1390
1477
|
|
|
1391
1478
|
TypedArrayOf(); ///< Creates a new _empty_ TypedArrayOf instance.
|
|
@@ -1432,13 +1519,37 @@ class DataView : public Object {
|
|
|
1432
1519
|
size_t byteOffset,
|
|
1433
1520
|
size_t byteLength);
|
|
1434
1521
|
|
|
1522
|
+
#ifdef NODE_API_EXPERIMENTAL_HAS_SHAREDARRAYBUFFER
|
|
1523
|
+
static DataView New(napi_env env, Napi::SharedArrayBuffer arrayBuffer);
|
|
1524
|
+
static DataView New(napi_env env,
|
|
1525
|
+
Napi::SharedArrayBuffer arrayBuffer,
|
|
1526
|
+
size_t byteOffset);
|
|
1527
|
+
static DataView New(napi_env env,
|
|
1528
|
+
Napi::SharedArrayBuffer arrayBuffer,
|
|
1529
|
+
size_t byteOffset,
|
|
1530
|
+
size_t byteLength);
|
|
1531
|
+
#endif
|
|
1532
|
+
|
|
1435
1533
|
static void CheckCast(napi_env env, napi_value value);
|
|
1436
1534
|
|
|
1437
1535
|
DataView(); ///< Creates a new _empty_ DataView instance.
|
|
1438
1536
|
DataView(napi_env env,
|
|
1439
1537
|
napi_value value); ///< Wraps a Node-API value primitive.
|
|
1440
1538
|
|
|
1441
|
-
|
|
1539
|
+
// Gets the backing `ArrayBuffer`.
|
|
1540
|
+
//
|
|
1541
|
+
// If this `DataView` is not backed by an `ArrayBuffer`, this method will
|
|
1542
|
+
// terminate the process with a fatal error when using
|
|
1543
|
+
// `NODE_ADDON_API_ENABLE_TYPE_CHECK_ON_AS` or exhibit undefined behavior
|
|
1544
|
+
// otherwise. Use `Buffer()` instead to get the backing buffer without
|
|
1545
|
+
// assuming its type.
|
|
1546
|
+
Napi::ArrayBuffer ArrayBuffer() const;
|
|
1547
|
+
|
|
1548
|
+
// Gets the backing buffer (an `ArrayBuffer` or `SharedArrayBuffer`).
|
|
1549
|
+
//
|
|
1550
|
+
// Use `IsArrayBuffer()` or `IsSharedArrayBuffer()` to check the type of the
|
|
1551
|
+
// backing buffer prior to casting with `As<T>()`.
|
|
1552
|
+
Napi::Value Buffer() const;
|
|
1442
1553
|
size_t ByteOffset()
|
|
1443
1554
|
const; ///< Gets the offset into the buffer where the array starts.
|
|
1444
1555
|
size_t ByteLength() const; ///< Gets the length of the array in bytes.
|
|
@@ -1715,7 +1826,7 @@ class ObjectReference : public Reference<Object> {
|
|
|
1715
1826
|
MaybeOrValue<bool> Set(const std::string& utf8name, napi_value value) const;
|
|
1716
1827
|
MaybeOrValue<bool> Set(const std::string& utf8name, Napi::Value value) const;
|
|
1717
1828
|
MaybeOrValue<bool> Set(const std::string& utf8name,
|
|
1718
|
-
std::string& utf8value) const;
|
|
1829
|
+
const std::string& utf8value) const;
|
|
1719
1830
|
MaybeOrValue<bool> Set(const std::string& utf8name, bool boolValue) const;
|
|
1720
1831
|
MaybeOrValue<bool> Set(const std::string& utf8name, double numberValue) const;
|
|
1721
1832
|
|
|
@@ -3109,8 +3220,8 @@ class AsyncProgressWorkerBase : public AsyncWorker {
|
|
|
3109
3220
|
|
|
3110
3221
|
AsyncProgressWorkerBase* asyncprogressworker() {
|
|
3111
3222
|
return _asyncprogressworker;
|
|
3112
|
-
}
|
|
3113
|
-
DataType* data() { return _data; }
|
|
3223
|
+
}
|
|
3224
|
+
DataType* data() { return _data; }
|
|
3114
3225
|
|
|
3115
3226
|
private:
|
|
3116
3227
|
AsyncProgressWorkerBase* _asyncprogressworker;
|
package/doc/variables.md
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# Variable definitions
|
|
2
|
-
|
|
3
|
-
*New in Koffi 2.6*
|
|
4
|
-
|
|
5
|
-
To find an exported and declare a variable, use `lib.symbol(name, type)`. You need to specify its name and its type.
|
|
6
|
-
|
|
7
|
-
```c
|
|
8
|
-
int my_int = 42;
|
|
9
|
-
const char *my_string = NULL;
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
```js
|
|
13
|
-
const my_int = lib.symbol('my_int', 'int');
|
|
14
|
-
const my_string = lib.symbol('my_string', 'const char *');
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
You cannot directly manipulate these variables, use:
|
|
18
|
-
|
|
19
|
-
- [koffi.decode()](#decode-to-js-values) to read their value
|
|
20
|
-
- [koffi.encode()](#encode-to-c-memory) to change their value
|
|
21
|
-
|
|
22
|
-
# Decode to JS values
|
|
23
|
-
|
|
24
|
-
*New in Koffi 2.2, changed in Koffi 2.3*
|
|
25
|
-
|
|
26
|
-
Use `koffi.decode()` to decode C pointers, represented by BigInt numbers.
|
|
27
|
-
|
|
28
|
-
Some arguments are optional and this function can be called in several ways:
|
|
29
|
-
|
|
30
|
-
- `koffi.decode(value, type)`: no offset
|
|
31
|
-
- `koffi.decode(value, offset, type)`: explicit offset to add to the pointer before decoding
|
|
32
|
-
|
|
33
|
-
By default, Koffi expects NUL terminated strings when decoding them. See below if you need to specify the string length.
|
|
34
|
-
|
|
35
|
-
The following example illustrates how to decode an integer and a C string variable.
|
|
36
|
-
|
|
37
|
-
```c
|
|
38
|
-
int my_int = 42;
|
|
39
|
-
const char *my_string = "foobar";
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
```js
|
|
43
|
-
const my_int = lib.symbol('my_int', 'int');
|
|
44
|
-
const my_string = lib.symbol('my_string', 'const char *');
|
|
45
|
-
|
|
46
|
-
console.log(koffi.decode(my_int, 'int')) // Prints 42
|
|
47
|
-
console.log(koffi.decode(my_string, 'const char *')) // Prints "foobar"
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
There is also an optional ending `length` argument that you can use in two cases:
|
|
51
|
-
|
|
52
|
-
- Use it to give the number of bytes to decode in non-NUL terminated strings: `koffi.decode(value, 'char *', 5)`
|
|
53
|
-
- Decode consecutive values into an array. For example, here is how you can decode an array with 3 float values: `koffi.decode(value, 'float', 3)`. This is equivalent to `koffi.decode(value, koffi.array('float', 3))`.
|
|
54
|
-
|
|
55
|
-
The example below will decode the symbol `my_string` defined above but only the first three bytes.
|
|
56
|
-
|
|
57
|
-
```js
|
|
58
|
-
// Only decode 3 bytes from the C string my_string
|
|
59
|
-
console.log(koffi.decode(my_string, 'const char *', 3)) // Prints "foo"
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
> [!NOTE]
|
|
63
|
-
> In Koffi 2.2 and earlier versions, the length argument is only used to decode strings and is ignored otherwise.
|
|
64
|
-
|
|
65
|
-
# Encode to C memory
|
|
66
|
-
|
|
67
|
-
*New in Koffi 2.6*
|
|
68
|
-
|
|
69
|
-
Use `koffi.encode()` to encode JS values into C symbols or pointers, which are represented by BigInt numbers.
|
|
70
|
-
|
|
71
|
-
Some arguments are optional and this function can be called in several ways:
|
|
72
|
-
|
|
73
|
-
- `koffi.encode(ptr, type, value)`: no offset
|
|
74
|
-
- `koffi.encode(ptr, offset, type, value)`: explicit offset to add to the pointer before encoding
|
|
75
|
-
|
|
76
|
-
We'll reuse the examples shown above and change the variable values with `koffi.encode()`.
|
|
77
|
-
|
|
78
|
-
```c
|
|
79
|
-
int my_int = 42;
|
|
80
|
-
const char *my_string = NULL;
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
```js
|
|
84
|
-
const my_int = lib.symbol('my_int', 'int');
|
|
85
|
-
const my_string = lib.symbol('my_string', 'const char *');
|
|
86
|
-
|
|
87
|
-
console.log(koffi.decode(my_int, 'int')) // Prints 42
|
|
88
|
-
console.log(koffi.decode(my_string, 'const char *')) // Prints null
|
|
89
|
-
|
|
90
|
-
koffi.encode(my_int, 'int', -1);
|
|
91
|
-
koffi.encode(my_string, 'const char *', 'Hello World!');
|
|
92
|
-
|
|
93
|
-
console.log(koffi.decode(my_int, 'int')) // Prints -1
|
|
94
|
-
console.log(koffi.decode(my_string, 'const char *')) // Prints "Hello World!"
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
When encoding strings (either directly or embedded in arrays or structs), the memory will be bound to the raw pointer value and managed by Koffi. You can assign to the same string again and again without any leak or risk of use-after-free.
|
|
98
|
-
|
|
99
|
-
There is also an optional ending `length` argument that you can use to encode an array. For example, here is how you can encode an array with 3 float values: `koffi.encode(symbol, 'float', [1, 2, 3], 3)`. This is equivalent to `koffi.encode(symbol, koffi.array('float', 3), [1, 2, 3])`.
|
|
100
|
-
|
|
101
|
-
> [!NOTE]
|
|
102
|
-
> The length argument did not work correctly before Koffi 2.6.11.
|
package/indirect.d.ts
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
// SPDX-FileCopyrightText: 2026 Niels Martignène <niels.martignene@protonmail.com>
|
|
3
|
-
|
|
4
|
-
declare module "koffi/indirect" {
|
|
5
|
-
type PrimitiveKind = 'Void' | 'Bool' | 'Int8' | 'UInt8' | 'Int16' | 'Int16S' | 'UInt16' | 'UInt16S' |
|
|
6
|
-
'Int32' | 'Int32S' | 'UInt32' | 'UInt32S' | 'Int64' | 'Int64S' | 'UInt64' | 'UInt64S' |
|
|
7
|
-
'String' | 'String16' | 'Pointer' | 'Record' | 'Union' | 'Array' | 'Float32' | 'Float64' |
|
|
8
|
-
'Prototype' | 'Callback';
|
|
9
|
-
type ArrayHint = 'Array' | 'Typed' | 'String';
|
|
10
|
-
|
|
11
|
-
type PrototypeInfo = {
|
|
12
|
-
name: string;
|
|
13
|
-
arguments: TypeObject[];
|
|
14
|
-
result: TypeObject
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
interface IKoffiDirectionMarker { __brand: 'IKoffiDirectionMarker' }
|
|
18
|
-
interface IKoffiPointerCast { __brand: 'IKoffiPointerCast' }
|
|
19
|
-
|
|
20
|
-
export type TypeObject = {
|
|
21
|
-
name: string;
|
|
22
|
-
primitive: PrimitiveKind;
|
|
23
|
-
size: number;
|
|
24
|
-
alignment: number;
|
|
25
|
-
disposable: boolean;
|
|
26
|
-
length?: number;
|
|
27
|
-
hint?: ArrayHint;
|
|
28
|
-
ref?: TypeObject;
|
|
29
|
-
members?: Record<string, { name: string, type: TypeObject, offset: number }>;
|
|
30
|
-
proto?: PrototypeInfo;
|
|
31
|
-
values?: Record<string, number | bigint>;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
type TypeSpec = string | TypeObject | IKoffiDirectionMarker;
|
|
35
|
-
type TypeSpecWithAlignment = TypeSpec | [number, TypeSpec];
|
|
36
|
-
|
|
37
|
-
type KoffiFunction = {
|
|
38
|
-
(...args: any[]) : any;
|
|
39
|
-
async: (...args: any[]) => any;
|
|
40
|
-
info: PrototypeInfo;
|
|
41
|
-
};
|
|
42
|
-
export type KoffiFunc<T extends (...args: any) => any> = T & {
|
|
43
|
-
async: (...args: [...Parameters<T>, (err: any, result: ReturnType<T>) => void]) => void;
|
|
44
|
-
info: PrototypeInfo;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
type LoadOptions = {
|
|
48
|
-
lazy?: boolean,
|
|
49
|
-
global?: boolean,
|
|
50
|
-
deep?: boolean
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export type LibraryHandle = {
|
|
54
|
-
func(definition: string): KoffiFunction;
|
|
55
|
-
func(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
56
|
-
func(convention: string, name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
57
|
-
|
|
58
|
-
/** @deprecated */ cdecl(definition: string): KoffiFunction;
|
|
59
|
-
/** @deprecated */ cdecl(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
60
|
-
/** @deprecated */ stdcall(definition: string): KoffiFunction;
|
|
61
|
-
/** @deprecated */ stdcall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
62
|
-
/** @deprecated */ fastcall(definition: string): KoffiFunction;
|
|
63
|
-
/** @deprecated */ fastcall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
64
|
-
/** @deprecated */ thiscall(definition: string): KoffiFunction;
|
|
65
|
-
/** @deprecated */ thiscall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
66
|
-
|
|
67
|
-
symbol(name: string, type: TypeSpec): any;
|
|
68
|
-
|
|
69
|
-
unload(): void;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export function load(path: string | null, options?: LoadOptions): LibraryHandle;
|
|
73
|
-
|
|
74
|
-
export function struct(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
75
|
-
export function struct(ref: TypeObject, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
76
|
-
export function struct(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
77
|
-
export function pack(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
78
|
-
export function pack(ref: TypeObject, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
79
|
-
export function pack(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
80
|
-
|
|
81
|
-
export function union(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
82
|
-
export function union(ref: TypeObject, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
83
|
-
export function union(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
84
|
-
|
|
85
|
-
export class Union {
|
|
86
|
-
constructor(type: TypeSpec);
|
|
87
|
-
[s: string]: any;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function enumeration(name: string | null | undefined, def: Record<string, number | bigint>, storage?: TypeSpec | null) : TypeObject;
|
|
91
|
-
export function enumeration(def: Record<string, number | bigint>, storage?: TypeSpec | null) : TypeObject;
|
|
92
|
-
|
|
93
|
-
export function array(ref: TypeSpec, len: number, hint?: ArrayHint | null): TypeObject;
|
|
94
|
-
export function array(ref: TypeSpec, countedBy: string, maxLen: number, hint?: ArrayHint | null): TypeObject;
|
|
95
|
-
|
|
96
|
-
export function opaque(name: string | null | undefined): TypeObject;
|
|
97
|
-
export function opaque(): TypeObject;
|
|
98
|
-
|
|
99
|
-
export function pointer(ref: TypeSpec): TypeObject;
|
|
100
|
-
export function pointer(ref: TypeSpec, count: number): TypeObject;
|
|
101
|
-
export function pointer(name: string | null | undefined, ref: TypeSpec, countedBy?: string | null): TypeObject;
|
|
102
|
-
export function pointer(name: string | null | undefined, ref: TypeSpec, count: number): TypeObject;
|
|
103
|
-
|
|
104
|
-
export function out(type: TypeSpec): IKoffiDirectionMarker;
|
|
105
|
-
export function inout(type: TypeSpec): IKoffiDirectionMarker;
|
|
106
|
-
|
|
107
|
-
export function disposable(type: TypeSpec): TypeObject;
|
|
108
|
-
export function disposable(type: TypeSpec, freeFunction: Function): TypeObject;
|
|
109
|
-
export function disposable(name: string | null | undefined, type: TypeSpec): TypeObject;
|
|
110
|
-
export function disposable(name: string | null | undefined, type: TypeSpec, freeFunction: Function): TypeObject;
|
|
111
|
-
|
|
112
|
-
export function proto(definition: string): TypeObject;
|
|
113
|
-
export function proto(result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
114
|
-
export function proto(convention: string, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
115
|
-
export function proto(name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
116
|
-
export function proto(convention: string, name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
117
|
-
|
|
118
|
-
export function register(callback: Function, type: TypeSpec): bigint;
|
|
119
|
-
/** @deprecated */ export function register(thisValue: any, callback: Function, type: TypeSpec): bigint;
|
|
120
|
-
export function unregister(callback: bigint): void;
|
|
121
|
-
|
|
122
|
-
export function as(value: any, type: TypeSpec): IKoffiPointerCast;
|
|
123
|
-
export function address(value: any): bigint;
|
|
124
|
-
export function call(value: any, type: TypeSpec, ...args: any[]): any;
|
|
125
|
-
export function view(ref: any, len: number): ArrayBuffer;
|
|
126
|
-
|
|
127
|
-
export const decode: {
|
|
128
|
-
(value: any, type: TypeSpec): any;
|
|
129
|
-
(value: any, type: TypeSpec, len: number): any;
|
|
130
|
-
(value: any, offset: number, type: TypeSpec): any;
|
|
131
|
-
(value: any, offset: number, type: TypeSpec, len: number): any;
|
|
132
|
-
|
|
133
|
-
char(ptr: any): number;
|
|
134
|
-
short(ptr: any): number;
|
|
135
|
-
int(ptr: any): number;
|
|
136
|
-
long(ptr: any): number | bigint;
|
|
137
|
-
longlong(ptr: any): number | bigint;
|
|
138
|
-
uchar(ptr: any): number;
|
|
139
|
-
ushort(ptr: any): number;
|
|
140
|
-
uint(ptr: any): number;
|
|
141
|
-
ulong(ptr: any): number | bigint;
|
|
142
|
-
ulonglong(ptr: any): number | bigint;
|
|
143
|
-
|
|
144
|
-
int8(ptr: any): number;
|
|
145
|
-
int16(ptr: any): number;
|
|
146
|
-
int32(ptr: any): number;
|
|
147
|
-
int64(ptr: any): number | bigint;
|
|
148
|
-
uint8(ptr: any): number;
|
|
149
|
-
uint16(ptr: any): number;
|
|
150
|
-
uint32(ptr: any): number;
|
|
151
|
-
uint64(ptr: any): number | bigint;
|
|
152
|
-
|
|
153
|
-
float(ptr: any): number;
|
|
154
|
-
double(ptr: any): number;
|
|
155
|
-
|
|
156
|
-
string(ptr: any, length?: number | bigint | null): string;
|
|
157
|
-
string16(ptr: any, length?: number | bigint | null): string;
|
|
158
|
-
string32(ptr: any, length?: number | bigint | null): string;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
export function encode(ref: any, type: TypeSpec, value: any): void;
|
|
162
|
-
export function encode(ref: any, type: TypeSpec, value: any, len: number): void;
|
|
163
|
-
export function encode(ref: any, offset: number, type: TypeSpec): void;
|
|
164
|
-
export function encode(ref: any, offset: number, type: TypeSpec, value: any): void;
|
|
165
|
-
export function encode(ref: any, offset: number, type: TypeSpec, value: any, len: number): void;
|
|
166
|
-
|
|
167
|
-
export function type(type: TypeSpec): TypeObject;
|
|
168
|
-
export function sizeof(type: TypeSpec): number;
|
|
169
|
-
export function alignof(type: TypeSpec): number;
|
|
170
|
-
export function offsetof(type: TypeSpec, member_name: string): number;
|
|
171
|
-
/** @deprecated */ export function resolve(type: TypeSpec): TypeObject;
|
|
172
|
-
/** @deprecated */ export function introspect(type: TypeSpec): TypeObject;
|
|
173
|
-
|
|
174
|
-
export function alias(name: string, type: TypeSpec): TypeObject;
|
|
175
|
-
|
|
176
|
-
type KoffiConfig = {
|
|
177
|
-
sync_stack_size?: number;
|
|
178
|
-
sync_heap_size?: number;
|
|
179
|
-
async_stack_size?: number;
|
|
180
|
-
async_heap_size?: number;
|
|
181
|
-
resident_async_pools?: number;
|
|
182
|
-
max_async_calls?: number;
|
|
183
|
-
max_type_size?: number;
|
|
184
|
-
};
|
|
185
|
-
type KoffiStats = {
|
|
186
|
-
disposed: number
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
export function config(): KoffiConfig;
|
|
190
|
-
export function config(cfg: KoffiConfig): KoffiConfig;
|
|
191
|
-
export function stats(): KoffiStats;
|
|
192
|
-
|
|
193
|
-
export function alloc(type: TypeSpec, length: number): any;
|
|
194
|
-
export function free(value: any): void;
|
|
195
|
-
|
|
196
|
-
export function errno(): number;
|
|
197
|
-
export function errno(value: number): number;
|
|
198
|
-
|
|
199
|
-
export function reset(): void;
|
|
200
|
-
|
|
201
|
-
export const internal: boolean;
|
|
202
|
-
export const extension: string;
|
|
203
|
-
|
|
204
|
-
export const os: {
|
|
205
|
-
errno: Record<string, number>
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
// https://koffi.dev/input#standard-types
|
|
209
|
-
type PrimitiveTypes =
|
|
210
|
-
| 'bool'
|
|
211
|
-
| 'char'
|
|
212
|
-
| 'char16_t'
|
|
213
|
-
| 'char16'
|
|
214
|
-
| 'char32_t'
|
|
215
|
-
| 'char32'
|
|
216
|
-
| 'double'
|
|
217
|
-
| 'float'
|
|
218
|
-
| 'float32'
|
|
219
|
-
| 'float64'
|
|
220
|
-
| 'int'
|
|
221
|
-
| 'int8_t'
|
|
222
|
-
| 'int8'
|
|
223
|
-
| 'int16_be_t'
|
|
224
|
-
| 'int16_be'
|
|
225
|
-
| 'int16_le_t'
|
|
226
|
-
| 'int16_le'
|
|
227
|
-
| 'int16_t'
|
|
228
|
-
| 'int16'
|
|
229
|
-
| 'int32_be_t'
|
|
230
|
-
| 'int32_be'
|
|
231
|
-
| 'int32_le_t'
|
|
232
|
-
| 'int32_le'
|
|
233
|
-
| 'int32_t'
|
|
234
|
-
| 'int32'
|
|
235
|
-
| 'int64_be_t'
|
|
236
|
-
| 'int64_be'
|
|
237
|
-
| 'int64_le_t'
|
|
238
|
-
| 'int64_le'
|
|
239
|
-
| 'int64_t'
|
|
240
|
-
| 'int64'
|
|
241
|
-
| 'intptr_t'
|
|
242
|
-
| 'intptr'
|
|
243
|
-
| 'long long'
|
|
244
|
-
| 'long'
|
|
245
|
-
| 'longlong'
|
|
246
|
-
| 'short'
|
|
247
|
-
| 'size_t'
|
|
248
|
-
| 'str'
|
|
249
|
-
| 'str16'
|
|
250
|
-
| 'str32'
|
|
251
|
-
| 'string'
|
|
252
|
-
| 'string16'
|
|
253
|
-
| 'string32'
|
|
254
|
-
| 'uchar'
|
|
255
|
-
| 'uint'
|
|
256
|
-
| 'uint8_t'
|
|
257
|
-
| 'uint8'
|
|
258
|
-
| 'uint16_be_t'
|
|
259
|
-
| 'uint16_be'
|
|
260
|
-
| 'uint16_le_t'
|
|
261
|
-
| 'uint16_le'
|
|
262
|
-
| 'uint16_t'
|
|
263
|
-
| 'uint16'
|
|
264
|
-
| 'uint32_be_t'
|
|
265
|
-
| 'uint32_be'
|
|
266
|
-
| 'uint32_le_t'
|
|
267
|
-
| 'uint32_le'
|
|
268
|
-
| 'uint32_t'
|
|
269
|
-
| 'uint32'
|
|
270
|
-
| 'uint64_be_t'
|
|
271
|
-
| 'uint64_be'
|
|
272
|
-
| 'uint64_le_t'
|
|
273
|
-
| 'uint64_le'
|
|
274
|
-
| 'uint64_t'
|
|
275
|
-
| 'uint64'
|
|
276
|
-
| 'uintptr_t'
|
|
277
|
-
| 'uintptr'
|
|
278
|
-
| 'ulong'
|
|
279
|
-
| 'ulonglong'
|
|
280
|
-
| 'unsigned char'
|
|
281
|
-
| 'unsigned int'
|
|
282
|
-
| 'unsigned long long'
|
|
283
|
-
| 'unsigned long'
|
|
284
|
-
| 'unsigned short'
|
|
285
|
-
| 'ushort'
|
|
286
|
-
| 'void'
|
|
287
|
-
| 'wchar'
|
|
288
|
-
| 'wchar_t';
|
|
289
|
-
export const types: Record<PrimitiveTypes, TypeObject>;
|
|
290
|
-
|
|
291
|
-
export namespace node {
|
|
292
|
-
export const env: { __brand: 'IKoffiNodeEnv' };
|
|
293
|
-
|
|
294
|
-
type PollOptions = {
|
|
295
|
-
readable?: boolean;
|
|
296
|
-
writable?: boolean;
|
|
297
|
-
disconnect?: boolean;
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
type PollEvents = {
|
|
301
|
-
readable: boolean;
|
|
302
|
-
writable: boolean;
|
|
303
|
-
disconnect: boolean;
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
export class PollHandle {
|
|
307
|
-
start(opts: PollOptions, callback: (ev: PollEvents) => void): void;
|
|
308
|
-
start(callback: (ev: PollEvents) => void): void;
|
|
309
|
-
stop(): void;
|
|
310
|
-
|
|
311
|
-
close(): void;
|
|
312
|
-
|
|
313
|
-
unref(): void;
|
|
314
|
-
ref(): void;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
export function poll(fd: number, opts: PollOptions, callback: (ev: PollEvents) => void): PollHandle;
|
|
318
|
-
export function poll(fd: number, callback: (ev: PollEvents) => void): PollHandle;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
export const version: string;
|
|
322
|
-
}
|