koffi 3.0.1 → 3.0.2
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 +11 -0
- package/cnoke.cjs +7 -7
- package/doc/benchmarks.md +1 -1
- package/doc/contribute.md +1 -1
- package/index.d.ts +356 -308
- package/package.json +16 -16
- package/src/koffi/CMakeLists.txt +1 -0
- package/src/koffi/index.cjs +30 -116
- package/src/koffi/index.js +27 -101
- package/src/koffi/indirect.cjs +29 -115
- package/src/koffi/indirect.js +28 -28
- package/src/koffi/src/abi/arm64.cc +1 -0
- package/src/koffi/src/abi/riscv64.cc +1 -0
- package/src/koffi/src/abi/x64sysv.cc +1 -0
- package/src/koffi/src/abi/x64win.cc +1 -0
- package/src/koffi/src/abi/x86.cc +1 -0
- package/src/koffi/src/call.cc +208 -97
- package/src/koffi/src/call.hh +2 -1
- package/src/koffi/src/ffi.cc +347 -237
- package/src/koffi/src/ffi.hh +37 -1
- package/src/koffi/src/parser.cc +3 -1
- package/src/koffi/src/static.cjs +122 -0
- package/src/koffi/src/static.js +122 -0
- package/src/koffi/src/type.cc +715 -0
- package/src/koffi/src/type.hh +71 -0
- package/src/koffi/src/util.cc +56 -1041
- package/src/koffi/src/util.hh +80 -119
- package/src/koffi/src/uv.cc +16 -10
- package/src/koffi/src/uv.hh +2 -1
- package/indirect.d.ts +0 -322
package/index.d.ts
CHANGED
|
@@ -1,322 +1,370 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
4
|
+
type PrimitiveKind = 'Void' | 'Bool' | 'Int8' | 'UInt8' | 'Int16' | 'Int16S' | 'UInt16' | 'UInt16S' |
|
|
5
|
+
'Int32' | 'Int32S' | 'UInt32' | 'UInt32S' | 'Int64' | 'Int64S' | 'UInt64' | 'UInt64S' |
|
|
6
|
+
'String' | 'String16' | 'Pointer' | 'Record' | 'Union' | 'Array' | 'Float32' | 'Float64' |
|
|
7
|
+
'Prototype' | 'Callback';
|
|
8
|
+
type ArrayHint = 'Array' | 'Typed' | 'Buffer' | 'String';
|
|
9
|
+
|
|
10
|
+
type PrototypeInfo = {
|
|
11
|
+
name: string;
|
|
12
|
+
arguments: TypeObject[];
|
|
13
|
+
result: TypeObject
|
|
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
|
+
|
|
71
|
+
export function load(path: string | null, options?: LoadOptions): LibraryHandle;
|
|
72
|
+
|
|
73
|
+
export function struct(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
74
|
+
export function struct(ref: TypeObject, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
75
|
+
export function struct(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
76
|
+
export function pack(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
77
|
+
export function pack(ref: TypeObject, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
78
|
+
export function pack(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
79
|
+
|
|
80
|
+
export function union(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
81
|
+
export function union(ref: TypeObject, def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
82
|
+
export function union(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
83
|
+
|
|
84
|
+
export class Union {
|
|
85
|
+
constructor(type: TypeSpec);
|
|
86
|
+
[s: string]: any;
|
|
87
|
+
}
|
|
46
88
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
89
|
+
export function enumeration(name: string | null | undefined, def: Record<string, number | bigint>, storage?: TypeSpec | null) : TypeObject;
|
|
90
|
+
export function enumeration(def: Record<string, number | bigint>, storage?: TypeSpec | null) : TypeObject;
|
|
91
|
+
|
|
92
|
+
export function array(ref: TypeSpec, len: number, hint?: ArrayHint | null): TypeObject;
|
|
93
|
+
export function array(ref: TypeSpec, countedBy: string, maxLen: number, hint?: ArrayHint | null): TypeObject;
|
|
94
|
+
|
|
95
|
+
export function opaque(name: string | null | undefined): TypeObject;
|
|
96
|
+
export function opaque(): TypeObject;
|
|
97
|
+
|
|
98
|
+
export function pointer(ref: TypeSpec): TypeObject;
|
|
99
|
+
export function pointer(ref: TypeSpec, count: number): TypeObject;
|
|
100
|
+
export function pointer(name: string | null | undefined, ref: TypeSpec, countedBy?: string | null): TypeObject;
|
|
101
|
+
export function pointer(name: string | null | undefined, ref: TypeSpec, count: number): TypeObject;
|
|
102
|
+
|
|
103
|
+
export function out(type: TypeSpec): IKoffiDirectionMarker;
|
|
104
|
+
export function inout(type: TypeSpec): IKoffiDirectionMarker;
|
|
105
|
+
|
|
106
|
+
export function disposable(type: TypeSpec): TypeObject;
|
|
107
|
+
export function disposable(type: TypeSpec, freeFunction: Function): TypeObject;
|
|
108
|
+
export function disposable(name: string | null | undefined, type: TypeSpec): TypeObject;
|
|
109
|
+
export function disposable(name: string | null | undefined, type: TypeSpec, freeFunction: Function): TypeObject;
|
|
110
|
+
|
|
111
|
+
export function proto(definition: string): TypeObject;
|
|
112
|
+
export function proto(result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
113
|
+
export function proto(convention: string, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
114
|
+
export function proto(name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
115
|
+
export function proto(convention: string, name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): TypeObject;
|
|
116
|
+
|
|
117
|
+
export function register(callback: Function, type: TypeSpec): bigint;
|
|
118
|
+
/** @deprecated */ export function register(thisValue: any, callback: Function, type: TypeSpec): bigint;
|
|
119
|
+
export function unregister(callback: bigint): void;
|
|
120
|
+
|
|
121
|
+
export function as(value: any, type: TypeSpec): IKoffiPointerCast;
|
|
122
|
+
export function address(value: any): bigint;
|
|
123
|
+
export function call(value: any, type: TypeSpec, ...args: any[]): any;
|
|
124
|
+
export function view(ref: any, len: number): ArrayBuffer;
|
|
125
|
+
|
|
126
|
+
export const decode: {
|
|
127
|
+
(value: any, type: TypeSpec): any;
|
|
128
|
+
(value: any, type: TypeSpec, len: number): any;
|
|
129
|
+
(value: any, offset: number, type: TypeSpec): any;
|
|
130
|
+
(value: any, offset: number, type: TypeSpec, len: number): any;
|
|
131
|
+
|
|
132
|
+
char(ptr: any): number;
|
|
133
|
+
short(ptr: any): number;
|
|
134
|
+
int(ptr: any): number;
|
|
135
|
+
long(ptr: any): number | bigint;
|
|
136
|
+
longlong(ptr: any): number | bigint;
|
|
137
|
+
uchar(ptr: any): number;
|
|
138
|
+
ushort(ptr: any): number;
|
|
139
|
+
uint(ptr: any): number;
|
|
140
|
+
ulong(ptr: any): number | bigint;
|
|
141
|
+
ulonglong(ptr: any): number | bigint;
|
|
142
|
+
|
|
143
|
+
int8(ptr: any): number;
|
|
144
|
+
int16(ptr: any): number;
|
|
145
|
+
int32(ptr: any): number;
|
|
146
|
+
int64(ptr: any): number | bigint;
|
|
147
|
+
uint8(ptr: any): number;
|
|
148
|
+
uint16(ptr: any): number;
|
|
149
|
+
uint32(ptr: any): number;
|
|
150
|
+
uint64(ptr: any): number | bigint;
|
|
151
|
+
|
|
152
|
+
float(ptr: any): number;
|
|
153
|
+
double(ptr: any): number;
|
|
154
|
+
|
|
155
|
+
string(ptr: any, length?: number | bigint | null): string;
|
|
156
|
+
string16(ptr: any, length?: number | bigint | null): string;
|
|
157
|
+
string32(ptr: any, length?: number | bigint | null): string;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export function encode(ref: any, type: TypeSpec, value: any): void;
|
|
161
|
+
export function encode(ref: any, type: TypeSpec, value: any, len: number): void;
|
|
162
|
+
export function encode(ref: any, offset: number, type: TypeSpec): void;
|
|
163
|
+
export function encode(ref: any, offset: number, type: TypeSpec, value: any): void;
|
|
164
|
+
export function encode(ref: any, offset: number, type: TypeSpec, value: any, len: number): void;
|
|
165
|
+
|
|
166
|
+
export function type(type: TypeSpec): TypeObject;
|
|
167
|
+
export function sizeof(type: TypeSpec): number;
|
|
168
|
+
export function alignof(type: TypeSpec): number;
|
|
169
|
+
export function offsetof(type: TypeSpec, member_name: string): number;
|
|
170
|
+
/** @deprecated */ export function resolve(type: TypeSpec): TypeObject;
|
|
171
|
+
/** @deprecated */ export function introspect(type: TypeSpec): TypeObject;
|
|
172
|
+
|
|
173
|
+
export function alias(name: string, type: TypeSpec): TypeObject;
|
|
174
|
+
|
|
175
|
+
type KoffiConfig = {
|
|
176
|
+
sync_stack_size?: number;
|
|
177
|
+
sync_heap_size?: number;
|
|
178
|
+
async_stack_size?: number;
|
|
179
|
+
async_heap_size?: number;
|
|
180
|
+
resident_async_pools?: number;
|
|
181
|
+
max_async_calls?: number;
|
|
182
|
+
max_type_size?: number;
|
|
183
|
+
};
|
|
184
|
+
type KoffiStats = {
|
|
185
|
+
disposed: number
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export function config(): KoffiConfig;
|
|
189
|
+
export function config(cfg: KoffiConfig): KoffiConfig;
|
|
190
|
+
export function stats(): KoffiStats;
|
|
191
|
+
|
|
192
|
+
export function alloc(type: TypeSpec, length: number): any;
|
|
193
|
+
export function free(value: any): void;
|
|
194
|
+
|
|
195
|
+
export function errno(): number;
|
|
196
|
+
export function errno(value: number): number;
|
|
197
|
+
|
|
198
|
+
export function reset(): void;
|
|
199
|
+
|
|
200
|
+
export const internal: boolean;
|
|
201
|
+
export const extension: string;
|
|
202
|
+
|
|
203
|
+
export const os: {
|
|
204
|
+
errno: Record<string, number>
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// https://koffi.dev/input#standard-types
|
|
208
|
+
type PrimitiveTypes =
|
|
209
|
+
| 'bool'
|
|
210
|
+
| 'char'
|
|
211
|
+
| 'char16_t'
|
|
212
|
+
| 'char16'
|
|
213
|
+
| 'char32_t'
|
|
214
|
+
| 'char32'
|
|
215
|
+
| 'double'
|
|
216
|
+
| 'float'
|
|
217
|
+
| 'float32'
|
|
218
|
+
| 'float64'
|
|
219
|
+
| 'int'
|
|
220
|
+
| 'int8_t'
|
|
221
|
+
| 'int8'
|
|
222
|
+
| 'int16_be_t'
|
|
223
|
+
| 'int16_be'
|
|
224
|
+
| 'int16_le_t'
|
|
225
|
+
| 'int16_le'
|
|
226
|
+
| 'int16_t'
|
|
227
|
+
| 'int16'
|
|
228
|
+
| 'int32_be_t'
|
|
229
|
+
| 'int32_be'
|
|
230
|
+
| 'int32_le_t'
|
|
231
|
+
| 'int32_le'
|
|
232
|
+
| 'int32_t'
|
|
233
|
+
| 'int32'
|
|
234
|
+
| 'int64_be_t'
|
|
235
|
+
| 'int64_be'
|
|
236
|
+
| 'int64_le_t'
|
|
237
|
+
| 'int64_le'
|
|
238
|
+
| 'int64_t'
|
|
239
|
+
| 'int64'
|
|
240
|
+
| 'intptr_t'
|
|
241
|
+
| 'intptr'
|
|
242
|
+
| 'long long'
|
|
243
|
+
| 'long'
|
|
244
|
+
| 'longlong'
|
|
245
|
+
| 'short'
|
|
246
|
+
| 'size_t'
|
|
247
|
+
| 'str'
|
|
248
|
+
| 'str16'
|
|
249
|
+
| 'str32'
|
|
250
|
+
| 'string'
|
|
251
|
+
| 'string16'
|
|
252
|
+
| 'string32'
|
|
253
|
+
| 'uchar'
|
|
254
|
+
| 'uint'
|
|
255
|
+
| 'uint8_t'
|
|
256
|
+
| 'uint8'
|
|
257
|
+
| 'uint16_be_t'
|
|
258
|
+
| 'uint16_be'
|
|
259
|
+
| 'uint16_le_t'
|
|
260
|
+
| 'uint16_le'
|
|
261
|
+
| 'uint16_t'
|
|
262
|
+
| 'uint16'
|
|
263
|
+
| 'uint32_be_t'
|
|
264
|
+
| 'uint32_be'
|
|
265
|
+
| 'uint32_le_t'
|
|
266
|
+
| 'uint32_le'
|
|
267
|
+
| 'uint32_t'
|
|
268
|
+
| 'uint32'
|
|
269
|
+
| 'uint64_be_t'
|
|
270
|
+
| 'uint64_be'
|
|
271
|
+
| 'uint64_le_t'
|
|
272
|
+
| 'uint64_le'
|
|
273
|
+
| 'uint64_t'
|
|
274
|
+
| 'uint64'
|
|
275
|
+
| 'uintptr_t'
|
|
276
|
+
| 'uintptr'
|
|
277
|
+
| 'ulong'
|
|
278
|
+
| 'ulonglong'
|
|
279
|
+
| 'unsigned char'
|
|
280
|
+
| 'unsigned int'
|
|
281
|
+
| 'unsigned long long'
|
|
282
|
+
| 'unsigned long'
|
|
283
|
+
| 'unsigned short'
|
|
284
|
+
| 'ushort'
|
|
285
|
+
| 'void'
|
|
286
|
+
| 'wchar'
|
|
287
|
+
| 'wchar_t';
|
|
288
|
+
export const types: Record<PrimitiveTypes, TypeObject>;
|
|
289
|
+
|
|
290
|
+
export namespace node {
|
|
291
|
+
export const env: { __brand: 'IKoffiNodeEnv' };
|
|
292
|
+
|
|
293
|
+
type PollOptions = {
|
|
294
|
+
readable?: boolean;
|
|
295
|
+
writable?: boolean;
|
|
296
|
+
disconnect?: boolean;
|
|
51
297
|
};
|
|
52
298
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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;
|
|
299
|
+
type PollEvents = {
|
|
300
|
+
readable: boolean;
|
|
301
|
+
writable: boolean;
|
|
302
|
+
disconnect: boolean;
|
|
70
303
|
};
|
|
71
304
|
|
|
72
|
-
export
|
|
305
|
+
export class PollHandle {
|
|
306
|
+
start(opts: PollOptions, callback: (ev: PollEvents) => void): void;
|
|
307
|
+
start(callback: (ev: PollEvents) => void): void;
|
|
308
|
+
stop(): void;
|
|
73
309
|
|
|
74
|
-
|
|
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;
|
|
310
|
+
close(): void;
|
|
80
311
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export function union(def: Record<string, TypeSpecWithAlignment>): TypeObject;
|
|
84
|
-
|
|
85
|
-
export class Union {
|
|
86
|
-
constructor(type: TypeSpec);
|
|
87
|
-
[s: string]: any;
|
|
312
|
+
unref(): void;
|
|
313
|
+
ref(): void;
|
|
88
314
|
}
|
|
89
315
|
|
|
90
|
-
export function
|
|
91
|
-
export function
|
|
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
|
-
}
|
|
316
|
+
export function poll(fd: number, opts: PollOptions, callback: (ev: PollEvents) => void): PollHandle;
|
|
317
|
+
export function poll(fd: number, callback: (ev: PollEvents) => void): PollHandle;
|
|
318
|
+
}
|
|
320
319
|
|
|
321
|
-
|
|
320
|
+
export const version: string;
|
|
321
|
+
|
|
322
|
+
// We want the same module with a default export and named exports.
|
|
323
|
+
// If someone knows a better way, feel free to help ;)
|
|
324
|
+
|
|
325
|
+
declare const DefaultObject: {
|
|
326
|
+
LibraryHandle: LibraryHandle;
|
|
327
|
+
TypeObject: TypeObject;
|
|
328
|
+
Union: Union;
|
|
329
|
+
|
|
330
|
+
address: typeof address;
|
|
331
|
+
alias: typeof alias;
|
|
332
|
+
alignof: typeof alignof;
|
|
333
|
+
alloc: typeof alloc;
|
|
334
|
+
array: typeof array;
|
|
335
|
+
as: typeof as;
|
|
336
|
+
call: typeof call;
|
|
337
|
+
config: typeof config;
|
|
338
|
+
decode: typeof decode;
|
|
339
|
+
disposable: typeof disposable;
|
|
340
|
+
encode: typeof encode;
|
|
341
|
+
enumeration: typeof enumeration;
|
|
342
|
+
errno: typeof errno;
|
|
343
|
+
extension: typeof extension;
|
|
344
|
+
free: typeof free;
|
|
345
|
+
inout: typeof inout;
|
|
346
|
+
introspect: typeof introspect;
|
|
347
|
+
load: typeof load;
|
|
348
|
+
node: typeof node;
|
|
349
|
+
offsetof: typeof offsetof;
|
|
350
|
+
opaque: typeof opaque;
|
|
351
|
+
os: typeof os;
|
|
352
|
+
out: typeof out;
|
|
353
|
+
pack: typeof pack;
|
|
354
|
+
pointer: typeof pointer;
|
|
355
|
+
proto: typeof proto;
|
|
356
|
+
register: typeof register;
|
|
357
|
+
reset: typeof reset;
|
|
358
|
+
resolve: typeof resolve;
|
|
359
|
+
sizeof: typeof sizeof;
|
|
360
|
+
stats: typeof stats;
|
|
361
|
+
struct: typeof struct;
|
|
362
|
+
type: typeof type;
|
|
363
|
+
types: typeof types;
|
|
364
|
+
union: typeof union;
|
|
365
|
+
unregister: typeof unregister;
|
|
366
|
+
version: typeof version;
|
|
367
|
+
view: typeof view;
|
|
322
368
|
}
|
|
369
|
+
|
|
370
|
+
export default DefaultObject;
|