koffi 3.0.0 → 3.0.1
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 +9 -1
- package/README.md +5 -4
- package/cnoke.cjs +3 -3
- package/doc/benchmarks.md +23 -46
- package/doc/callbacks.md +4 -13
- package/doc/contribute.md +3 -3
- package/doc/index.md +3 -2
- package/doc/migration.md +100 -0
- package/doc/start.md +7 -5
- package/index.d.ts +308 -308
- package/index.js +2 -1
- package/indirect.d.ts +322 -0
- package/indirect.js +2 -1
- package/package.json +20 -18
- package/src/koffi/CMakeLists.txt +19 -12
- package/src/koffi/index.cjs +65 -16
- package/src/koffi/index.js +105 -16
- package/src/koffi/indirect.cjs +65 -16
- package/src/koffi/indirect.js +105 -16
- package/src/koffi/src/abi/arm64.cc +29 -29
- package/src/koffi/src/abi/riscv64.cc +29 -29
- package/src/koffi/src/abi/x64sysv.cc +25 -25
- package/src/koffi/src/abi/x64win.cc +63 -63
- package/src/koffi/src/abi/x86.cc +66 -65
- package/src/koffi/src/call.cc +2 -2
- package/src/koffi/src/ffi.cc +64 -8
- package/src/koffi/src/ffi.hh +9 -6
- package/src/koffi/src/primitives.inc +1 -4
- package/src/koffi/src/util.cc +175 -121
- package/src/koffi/src/util.hh +13 -14
package/index.d.ts
CHANGED
|
@@ -1,322 +1,322 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// SPDX-FileCopyrightText: 2026 Niels Martignène <niels.martignene@protonmail.com>
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
interface IKoffiDirectionMarker { __brand: 'IKoffiDirectionMarker' }
|
|
17
|
-
interface IKoffiPointerCast { __brand: 'IKoffiPointerCast' }
|
|
18
|
-
|
|
19
|
-
export type TypeObject = {
|
|
20
|
-
name: string;
|
|
21
|
-
primitive: PrimitiveKind;
|
|
22
|
-
size: number;
|
|
23
|
-
alignment: number;
|
|
24
|
-
disposable: boolean;
|
|
25
|
-
length?: number;
|
|
26
|
-
hint?: ArrayHint;
|
|
27
|
-
ref?: TypeObject;
|
|
28
|
-
members?: Record<string, { name: string, type: TypeObject, offset: number }>;
|
|
29
|
-
proto?: PrototypeInfo;
|
|
30
|
-
values?: Record<string, number | bigint>;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
type TypeSpec = string | TypeObject | IKoffiDirectionMarker;
|
|
34
|
-
type TypeSpecWithAlignment = TypeSpec | [number, TypeSpec];
|
|
35
|
-
|
|
36
|
-
type KoffiFunction = {
|
|
37
|
-
(...args: any[]) : any;
|
|
38
|
-
async: (...args: any[]) => any;
|
|
39
|
-
info: PrototypeInfo;
|
|
40
|
-
};
|
|
41
|
-
export type KoffiFunc<T extends (...args: any) => any> = T & {
|
|
42
|
-
async: (...args: [...Parameters<T>, (err: any, result: ReturnType<T>) => void]) => void;
|
|
43
|
-
info: PrototypeInfo;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
type LoadOptions = {
|
|
47
|
-
lazy?: boolean,
|
|
48
|
-
global?: boolean,
|
|
49
|
-
deep?: boolean
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export type LibraryHandle = {
|
|
53
|
-
func(definition: string): KoffiFunction;
|
|
54
|
-
func(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
55
|
-
func(convention: string, name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
56
|
-
|
|
57
|
-
/** @deprecated */ cdecl(definition: string): KoffiFunction;
|
|
58
|
-
/** @deprecated */ cdecl(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
59
|
-
/** @deprecated */ stdcall(definition: string): KoffiFunction;
|
|
60
|
-
/** @deprecated */ stdcall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
61
|
-
/** @deprecated */ fastcall(definition: string): KoffiFunction;
|
|
62
|
-
/** @deprecated */ fastcall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
63
|
-
/** @deprecated */ thiscall(definition: string): KoffiFunction;
|
|
64
|
-
/** @deprecated */ thiscall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
|
|
65
|
-
|
|
66
|
-
symbol(name: string, type: TypeSpec): any;
|
|
67
|
-
|
|
68
|
-
unload(): void;
|
|
69
|
-
|
|
70
|
-
[Symbol.dispose](): void;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export function load(path: string | null, options?: LoadOptions): LibraryHandle;
|
|
74
|
-
|
|
75
|
-
export function struct(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
76
|
-
export function struct(ref: TypeObject, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
77
|
-
export function struct(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
78
|
-
export function pack(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
79
|
-
export function pack(ref: TypeObject, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
80
|
-
export function pack(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
81
|
-
|
|
82
|
-
export function union(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
83
|
-
export function union(ref: TypeObject, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
84
|
-
export function union(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
85
|
-
|
|
86
|
-
export class Union {
|
|
87
|
-
constructor(type: TypeSpec);
|
|
88
|
-
[s: string]: any;
|
|
89
|
-
}
|
|
4
|
+
declare module "koffi" {
|
|
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
|
+
};
|
|
90
16
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
export
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
export function inout(type: TypeSpec): IKoffiDirectionMarker;
|
|
107
|
-
|
|
108
|
-
export function disposable(type: TypeSpec): TypeObject;
|
|
109
|
-
export function disposable(type: TypeSpec, freeFunction: Function): TypeObject;
|
|
110
|
-
export function disposable(name: string | null | undefined, type: TypeSpec): TypeObject;
|
|
111
|
-
export function disposable(name: string | null | undefined, type: TypeSpec, freeFunction: Function): TypeObject;
|
|
112
|
-
|
|
113
|
-
export function proto(definition: string): TypeObject;
|
|
114
|
-
export function proto(result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
115
|
-
export function proto(convention: string, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
116
|
-
export function proto(name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
117
|
-
export function proto(convention: string, name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
118
|
-
|
|
119
|
-
export function register(callback: Function, type: TypeSpec): bigint;
|
|
120
|
-
/** @deprecated */ export function register(thisValue: any, callback: Function, type: TypeSpec): bigint;
|
|
121
|
-
export function unregister(callback: bigint): void;
|
|
122
|
-
|
|
123
|
-
export function as(value: any, type: TypeSpec): IKoffiPointerCast;
|
|
124
|
-
export function address(value: any): bigint;
|
|
125
|
-
export function call(value: any, type: TypeSpec, ...args: any[]): any;
|
|
126
|
-
export function view(ref: any, len: number): ArrayBuffer;
|
|
127
|
-
|
|
128
|
-
export const decode: {
|
|
129
|
-
(value: any, type: TypeSpec): any;
|
|
130
|
-
(value: any, type: TypeSpec, len: number): any;
|
|
131
|
-
(value: any, offset: number, type: TypeSpec): any;
|
|
132
|
-
(value: any, offset: number, type: TypeSpec, len: number): any;
|
|
133
|
-
|
|
134
|
-
char(ptr: any): number;
|
|
135
|
-
short(ptr: any): number;
|
|
136
|
-
int(ptr: any): number;
|
|
137
|
-
long(ptr: any): number | bigint;
|
|
138
|
-
longlong(ptr: any): number | bigint;
|
|
139
|
-
uchar(ptr: any): number;
|
|
140
|
-
ushort(ptr: any): number;
|
|
141
|
-
uint(ptr: any): number;
|
|
142
|
-
ulong(ptr: any): number | bigint;
|
|
143
|
-
ulonglong(ptr: any): number | bigint;
|
|
144
|
-
|
|
145
|
-
int8(ptr: any): number;
|
|
146
|
-
int16(ptr: any): number;
|
|
147
|
-
int32(ptr: any): number;
|
|
148
|
-
int64(ptr: any): number | bigint;
|
|
149
|
-
uint8(ptr: any): number;
|
|
150
|
-
uint16(ptr: any): number;
|
|
151
|
-
uint32(ptr: any): number;
|
|
152
|
-
uint64(ptr: any): number | bigint;
|
|
153
|
-
|
|
154
|
-
float(ptr: any): number;
|
|
155
|
-
double(ptr: any): number;
|
|
156
|
-
|
|
157
|
-
string(ptr: any, length?: number | bigint | null): string;
|
|
158
|
-
string16(ptr: any, length?: number | bigint | null): string;
|
|
159
|
-
string32(ptr: any, length?: number | bigint | null): string;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
export function encode(ref: any, type: TypeSpec, value: any): void;
|
|
163
|
-
export function encode(ref: any, type: TypeSpec, value: any, len: number): void;
|
|
164
|
-
export function encode(ref: any, offset: number, type: TypeSpec): void;
|
|
165
|
-
export function encode(ref: any, offset: number, type: TypeSpec, value: any): void;
|
|
166
|
-
export function encode(ref: any, offset: number, type: TypeSpec, value: any, len: number): void;
|
|
167
|
-
|
|
168
|
-
export function type(type: TypeSpec): TypeObject;
|
|
169
|
-
export function sizeof(type: TypeSpec): number;
|
|
170
|
-
export function alignof(type: TypeSpec): number;
|
|
171
|
-
export function offsetof(type: TypeSpec, member_name: string): number;
|
|
172
|
-
/** @deprecated */ export function resolve(type: TypeSpec): TypeObject;
|
|
173
|
-
/** @deprecated */ export function introspect(type: TypeSpec): TypeObject;
|
|
174
|
-
|
|
175
|
-
export function alias(name: string, type: TypeSpec): TypeObject;
|
|
176
|
-
|
|
177
|
-
type KoffiConfig = {
|
|
178
|
-
sync_stack_size?: number;
|
|
179
|
-
sync_heap_size?: number;
|
|
180
|
-
async_stack_size?: number;
|
|
181
|
-
async_heap_size?: number;
|
|
182
|
-
resident_async_pools?: number;
|
|
183
|
-
max_async_calls?: number;
|
|
184
|
-
max_type_size?: number;
|
|
185
|
-
};
|
|
186
|
-
type KoffiStats = {
|
|
187
|
-
disposed: number
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
export function config(): KoffiConfig;
|
|
191
|
-
export function config(cfg: KoffiConfig): KoffiConfig;
|
|
192
|
-
export function stats(): KoffiStats;
|
|
193
|
-
|
|
194
|
-
export function alloc(type: TypeSpec, length: number): any;
|
|
195
|
-
export function free(value: any): void;
|
|
196
|
-
|
|
197
|
-
export function errno(): number;
|
|
198
|
-
export function errno(value: number): number;
|
|
199
|
-
|
|
200
|
-
export function reset(): void;
|
|
201
|
-
|
|
202
|
-
export const internal: boolean;
|
|
203
|
-
export const extension: string;
|
|
204
|
-
|
|
205
|
-
export const os: {
|
|
206
|
-
errno: Record<string, number>
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
// https://koffi.dev/input#standard-types
|
|
210
|
-
type PrimitiveTypes =
|
|
211
|
-
| 'bool'
|
|
212
|
-
| 'char'
|
|
213
|
-
| 'char16_t'
|
|
214
|
-
| 'char16'
|
|
215
|
-
| 'char32_t'
|
|
216
|
-
| 'char32'
|
|
217
|
-
| 'double'
|
|
218
|
-
| 'float'
|
|
219
|
-
| 'float32'
|
|
220
|
-
| 'float64'
|
|
221
|
-
| 'int'
|
|
222
|
-
| 'int8_t'
|
|
223
|
-
| 'int8'
|
|
224
|
-
| 'int16_be_t'
|
|
225
|
-
| 'int16_be'
|
|
226
|
-
| 'int16_le_t'
|
|
227
|
-
| 'int16_le'
|
|
228
|
-
| 'int16_t'
|
|
229
|
-
| 'int16'
|
|
230
|
-
| 'int32_be_t'
|
|
231
|
-
| 'int32_be'
|
|
232
|
-
| 'int32_le_t'
|
|
233
|
-
| 'int32_le'
|
|
234
|
-
| 'int32_t'
|
|
235
|
-
| 'int32'
|
|
236
|
-
| 'int64_be_t'
|
|
237
|
-
| 'int64_be'
|
|
238
|
-
| 'int64_le_t'
|
|
239
|
-
| 'int64_le'
|
|
240
|
-
| 'int64_t'
|
|
241
|
-
| 'int64'
|
|
242
|
-
| 'intptr_t'
|
|
243
|
-
| 'intptr'
|
|
244
|
-
| 'long long'
|
|
245
|
-
| 'long'
|
|
246
|
-
| 'longlong'
|
|
247
|
-
| 'short'
|
|
248
|
-
| 'size_t'
|
|
249
|
-
| 'str'
|
|
250
|
-
| 'str16'
|
|
251
|
-
| 'str32'
|
|
252
|
-
| 'string'
|
|
253
|
-
| 'string16'
|
|
254
|
-
| 'string32'
|
|
255
|
-
| 'uchar'
|
|
256
|
-
| 'uint'
|
|
257
|
-
| 'uint8_t'
|
|
258
|
-
| 'uint8'
|
|
259
|
-
| 'uint16_be_t'
|
|
260
|
-
| 'uint16_be'
|
|
261
|
-
| 'uint16_le_t'
|
|
262
|
-
| 'uint16_le'
|
|
263
|
-
| 'uint16_t'
|
|
264
|
-
| 'uint16'
|
|
265
|
-
| 'uint32_be_t'
|
|
266
|
-
| 'uint32_be'
|
|
267
|
-
| 'uint32_le_t'
|
|
268
|
-
| 'uint32_le'
|
|
269
|
-
| 'uint32_t'
|
|
270
|
-
| 'uint32'
|
|
271
|
-
| 'uint64_be_t'
|
|
272
|
-
| 'uint64_be'
|
|
273
|
-
| 'uint64_le_t'
|
|
274
|
-
| 'uint64_le'
|
|
275
|
-
| 'uint64_t'
|
|
276
|
-
| 'uint64'
|
|
277
|
-
| 'uintptr_t'
|
|
278
|
-
| 'uintptr'
|
|
279
|
-
| 'ulong'
|
|
280
|
-
| 'ulonglong'
|
|
281
|
-
| 'unsigned char'
|
|
282
|
-
| 'unsigned int'
|
|
283
|
-
| 'unsigned long long'
|
|
284
|
-
| 'unsigned long'
|
|
285
|
-
| 'unsigned short'
|
|
286
|
-
| 'ushort'
|
|
287
|
-
| 'void'
|
|
288
|
-
| 'wchar'
|
|
289
|
-
| 'wchar_t';
|
|
290
|
-
export const types: Record<PrimitiveTypes, TypeObject>;
|
|
291
|
-
|
|
292
|
-
export namespace node {
|
|
293
|
-
export const env: { __brand: 'IKoffiNodeEnv' };
|
|
294
|
-
|
|
295
|
-
type PollOptions = {
|
|
296
|
-
readable?: boolean;
|
|
297
|
-
writable?: boolean;
|
|
298
|
-
disconnect?: boolean;
|
|
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>;
|
|
299
32
|
};
|
|
300
33
|
|
|
301
|
-
type
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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;
|
|
305
45
|
};
|
|
306
46
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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;
|
|
311
66
|
|
|
312
|
-
|
|
67
|
+
symbol(name: string, type: TypeSpec): any;
|
|
313
68
|
|
|
314
|
-
|
|
315
|
-
|
|
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
|
+
};
|
|
316
207
|
|
|
317
|
-
|
|
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;
|
|
318
319
|
}
|
|
319
320
|
|
|
320
|
-
export
|
|
321
|
-
export function poll(fd: number, callback: (ev: PollEvents) => void): PollHandle;
|
|
321
|
+
export const version: string;
|
|
322
322
|
}
|
package/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from "./src/koffi/index.js";
|
|
1
|
+
export { default } from "./src/koffi/index.js";
|
|
2
|
+
export * from "./src/koffi/index.js";
|