@gtkx/native 0.21.0 → 1.0.0-rc.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/README.md +137 -34
- package/index.d.ts +190 -0
- package/index.js +723 -0
- package/init.js +3 -0
- package/main.d.ts +20 -0
- package/main.js +3 -0
- package/package.json +152 -21
- package/dist/index.d.ts +0 -91
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -133
- package/dist/index.js.map +0 -1
- package/dist/tsconfig.lib.tsbuildinfo +0 -1
- package/dist/types.d.ts +0 -161
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/index.ts +0 -152
- package/types.ts +0 -146
package/dist/types.d.ts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Opaque handle for a native value.
|
|
3
|
-
*
|
|
4
|
-
* Wraps GObject, Boxed, and Fundamental type instances.
|
|
5
|
-
* This branded type ensures type safety for native object references.
|
|
6
|
-
*/
|
|
7
|
-
export type NativeHandle = {
|
|
8
|
-
readonly __brand: "NativeHandle";
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Union of all possible FFI return value types.
|
|
12
|
-
*
|
|
13
|
-
* Returned by `call()` and `read()` where the concrete type
|
|
14
|
-
* depends on the type descriptor passed to the function.
|
|
15
|
-
*/
|
|
16
|
-
export type FfiValue = NativeHandle | number | string | boolean | FfiValue[] | null | undefined;
|
|
17
|
-
type Int8Type = {
|
|
18
|
-
type: "int8";
|
|
19
|
-
};
|
|
20
|
-
type Uint8Type = {
|
|
21
|
-
type: "uint8";
|
|
22
|
-
};
|
|
23
|
-
type Int16Type = {
|
|
24
|
-
type: "int16";
|
|
25
|
-
};
|
|
26
|
-
type Uint16Type = {
|
|
27
|
-
type: "uint16";
|
|
28
|
-
};
|
|
29
|
-
type Int32Type = {
|
|
30
|
-
type: "int32";
|
|
31
|
-
};
|
|
32
|
-
type Uint32Type = {
|
|
33
|
-
type: "uint32";
|
|
34
|
-
};
|
|
35
|
-
type Int64Type = {
|
|
36
|
-
type: "int64";
|
|
37
|
-
};
|
|
38
|
-
type Uint64Type = {
|
|
39
|
-
type: "uint64";
|
|
40
|
-
};
|
|
41
|
-
type Float32Type = {
|
|
42
|
-
type: "float32";
|
|
43
|
-
};
|
|
44
|
-
type Float64Type = {
|
|
45
|
-
type: "float64";
|
|
46
|
-
};
|
|
47
|
-
type EnumType = {
|
|
48
|
-
type: "enum";
|
|
49
|
-
library: string;
|
|
50
|
-
getTypeFn: string;
|
|
51
|
-
signed: boolean;
|
|
52
|
-
};
|
|
53
|
-
type FlagsType = {
|
|
54
|
-
type: "flags";
|
|
55
|
-
library: string;
|
|
56
|
-
getTypeFn: string;
|
|
57
|
-
signed: boolean;
|
|
58
|
-
};
|
|
59
|
-
type BooleanType = {
|
|
60
|
-
type: "boolean";
|
|
61
|
-
};
|
|
62
|
-
type Ownership = "full" | "borrowed";
|
|
63
|
-
type StringType = {
|
|
64
|
-
type: "string";
|
|
65
|
-
ownership: Ownership;
|
|
66
|
-
length?: number;
|
|
67
|
-
};
|
|
68
|
-
type GObjectType = {
|
|
69
|
-
type: "gobject";
|
|
70
|
-
ownership: Ownership;
|
|
71
|
-
};
|
|
72
|
-
type BoxedType = {
|
|
73
|
-
type: "boxed";
|
|
74
|
-
ownership: Ownership;
|
|
75
|
-
innerType: string;
|
|
76
|
-
library?: string;
|
|
77
|
-
getTypeFn?: string;
|
|
78
|
-
};
|
|
79
|
-
type StructType = {
|
|
80
|
-
type: "struct";
|
|
81
|
-
ownership: Ownership;
|
|
82
|
-
innerType: string;
|
|
83
|
-
size?: number;
|
|
84
|
-
};
|
|
85
|
-
type FundamentalType = {
|
|
86
|
-
type: "fundamental";
|
|
87
|
-
ownership: Ownership;
|
|
88
|
-
library: string;
|
|
89
|
-
refFn: string;
|
|
90
|
-
unrefFn: string;
|
|
91
|
-
typeName?: string;
|
|
92
|
-
};
|
|
93
|
-
type ArrayType = {
|
|
94
|
-
type: "array";
|
|
95
|
-
itemType: Type;
|
|
96
|
-
kind: "array" | "glist" | "gslist" | "gptrarray" | "garray" | "gbytearray" | "sized" | "fixed";
|
|
97
|
-
ownership: Ownership;
|
|
98
|
-
elementSize?: number;
|
|
99
|
-
sizeParamIndex?: number;
|
|
100
|
-
fixedSize?: number;
|
|
101
|
-
};
|
|
102
|
-
type HashTableType = {
|
|
103
|
-
type: "hashtable";
|
|
104
|
-
keyType: Type;
|
|
105
|
-
valueType: Type;
|
|
106
|
-
ownership: Ownership;
|
|
107
|
-
};
|
|
108
|
-
type RefType = {
|
|
109
|
-
type: "ref";
|
|
110
|
-
innerType: Type;
|
|
111
|
-
};
|
|
112
|
-
type UnicharType = {
|
|
113
|
-
type: "unichar";
|
|
114
|
-
};
|
|
115
|
-
type VoidType = {
|
|
116
|
-
type: "void";
|
|
117
|
-
};
|
|
118
|
-
export type CallbackType = {
|
|
119
|
-
type: "callback";
|
|
120
|
-
kind: "closure";
|
|
121
|
-
argTypes: Type[];
|
|
122
|
-
returnType: Type;
|
|
123
|
-
};
|
|
124
|
-
export type TrampolineType = {
|
|
125
|
-
type: "trampoline";
|
|
126
|
-
argTypes: Type[];
|
|
127
|
-
returnType: Type;
|
|
128
|
-
hasDestroy?: boolean;
|
|
129
|
-
userDataIndex?: number;
|
|
130
|
-
scope?: "call" | "notified" | "async" | "forever";
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Discriminated union of all FFI type descriptors.
|
|
134
|
-
*
|
|
135
|
-
* Describes how to marshal values between JavaScript and native code.
|
|
136
|
-
*/
|
|
137
|
-
export type Type = Int8Type | Uint8Type | Int16Type | Uint16Type | Int32Type | Uint32Type | Int64Type | Uint64Type | Float32Type | Float64Type | EnumType | FlagsType | BooleanType | StringType | GObjectType | BoxedType | StructType | FundamentalType | ArrayType | HashTableType | RefType | CallbackType | TrampolineType | UnicharType | VoidType;
|
|
138
|
-
/**
|
|
139
|
-
* An argument for an FFI call.
|
|
140
|
-
*
|
|
141
|
-
* Combines a value with its type information for marshaling.
|
|
142
|
-
*/
|
|
143
|
-
export type Arg = {
|
|
144
|
-
/** Type descriptor for marshaling */
|
|
145
|
-
type: Type;
|
|
146
|
-
/** The argument value */
|
|
147
|
-
value: unknown;
|
|
148
|
-
/** Whether the argument can be null/undefined */
|
|
149
|
-
optional?: boolean;
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* A mutable reference wrapper for out-parameters.
|
|
153
|
-
*
|
|
154
|
-
* @typeParam T - The type of the referenced value
|
|
155
|
-
*/
|
|
156
|
-
export type Ref<T> = {
|
|
157
|
-
readonly __brand: "Ref";
|
|
158
|
-
value: T;
|
|
159
|
-
};
|
|
160
|
-
export {};
|
|
161
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAA;CAAE,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;AAEhG,KAAK,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AACjC,KAAK,SAAS,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AACnC,KAAK,SAAS,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AACnC,KAAK,UAAU,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AACrC,KAAK,SAAS,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AACnC,KAAK,UAAU,GAAG;IA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AAEF,MAAM,MAAM,cAAc,GAAG;IACzB,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,EAAE,IAAI,EAAE,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,CAAC;CACrD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,IAAI,GACV,QAAQ,GACR,SAAS,GACT,SAAS,GACT,UAAU,GACV,SAAS,GACT,UAAU,GACV,SAAS,GACT,UAAU,GACV,WAAW,GACX,WAAW,GACX,QAAQ,GACR,SAAS,GACT,WAAW,GACX,UAAU,GACV,WAAW,GACX,SAAS,GACT,UAAU,GACV,eAAe,GACf,SAAS,GACT,aAAa,GACb,OAAO,GACP,YAAY,GACZ,cAAc,GACd,WAAW,GACX,QAAQ,CAAC;AAEf;;;;GAIG;AACH,MAAM,MAAM,GAAG,GAAG;IACd,qCAAqC;IACrC,IAAI,EAAE,IAAI,CAAC;IACX,yBAAyB;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,iDAAiD;IACjD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI;IACjB,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IACxB,KAAK,EAAE,CAAC,CAAC;CACZ,CAAC"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":""}
|
package/index.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { arch, platform } from "node:os";
|
|
3
|
-
import type { Arg, CallbackType, FfiValue, NativeHandle, Ref, Type } from "./types.js";
|
|
4
|
-
|
|
5
|
-
const require = createRequire(import.meta.url);
|
|
6
|
-
|
|
7
|
-
function loadNativeBinding() {
|
|
8
|
-
const currentPlatform = platform();
|
|
9
|
-
const currentArch = arch();
|
|
10
|
-
|
|
11
|
-
if (currentPlatform !== "linux") {
|
|
12
|
-
throw new Error(`Unsupported platform: ${currentPlatform}, only Linux is supported`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (currentArch !== "x64" && currentArch !== "arm64") {
|
|
16
|
-
throw new Error(`Unsupported architecture: ${currentArch}, only x64 and arm64 are supported`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const packageName = `@gtkx/native-linux-${currentArch}`;
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
return require(packageName);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
const originalError = error instanceof Error ? error.message : String(error);
|
|
25
|
-
throw new Error(`Failed to load native binding for ${currentPlatform}-${currentArch}: ${originalError}`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const native = loadNativeBinding();
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Creates a mutable reference wrapper.
|
|
33
|
-
*
|
|
34
|
-
* Used for out-parameters in FFI calls where the native function
|
|
35
|
-
* needs to write a value back.
|
|
36
|
-
*
|
|
37
|
-
* @typeParam T - The type of the referenced value
|
|
38
|
-
* @param value - Initial value
|
|
39
|
-
* @returns A reference object containing the value
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```tsx
|
|
43
|
-
* const errorRef = createRef<GError | null>(null);
|
|
44
|
-
* const result = someFunction(errorRef);
|
|
45
|
-
* if (errorRef.value) {
|
|
46
|
-
* console.error(errorRef.value.message);
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export function createRef<T>(value: T): Ref<T> {
|
|
51
|
-
return { value } as Ref<T>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Makes a low-level FFI call to a native library.
|
|
56
|
-
*
|
|
57
|
-
* This is the core FFI mechanism. Most code should use the generated
|
|
58
|
-
* bindings in `@gtkx/ffi` instead of calling this directly.
|
|
59
|
-
*
|
|
60
|
-
* @param library - Shared library name (e.g., "libgtk-4.so.1")
|
|
61
|
-
* @param symbol - Function symbol name
|
|
62
|
-
* @param args - Function arguments with type information
|
|
63
|
-
* @param returnType - Expected return type
|
|
64
|
-
* @returns The function return value
|
|
65
|
-
*/
|
|
66
|
-
export function call(library: string, symbol: string, args: Arg[], returnType: Type): FfiValue {
|
|
67
|
-
return native.call(library, symbol, args, returnType) as FfiValue;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Starts the GTK runtime and creates an application.
|
|
72
|
-
*
|
|
73
|
-
* @param appId - Application ID in reverse domain notation
|
|
74
|
-
* @param flags - Optional GIO application flags
|
|
75
|
-
* @returns Native application pointer
|
|
76
|
-
*
|
|
77
|
-
* @internal Use `@gtkx/ffi` start() instead
|
|
78
|
-
*/
|
|
79
|
-
export function start(appId: string, flags?: number): NativeHandle {
|
|
80
|
-
return native.start(appId, flags) as NativeHandle;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Stops the GTK runtime.
|
|
85
|
-
*
|
|
86
|
-
* @internal Use `@gtkx/ffi` stop() instead
|
|
87
|
-
*/
|
|
88
|
-
export function stop(): void {
|
|
89
|
-
native.stop();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Reads a value from native memory.
|
|
94
|
-
*
|
|
95
|
-
* @param handle - Native handle pointing to the memory
|
|
96
|
-
* @param type - Type of value to read
|
|
97
|
-
* @param offset - Byte offset from the handle pointer
|
|
98
|
-
* @returns The read value
|
|
99
|
-
*/
|
|
100
|
-
export function read(handle: NativeHandle, type: Type, offset: number): FfiValue {
|
|
101
|
-
return native.read(handle, type, offset) as FfiValue;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Writes a value to native memory.
|
|
106
|
-
*
|
|
107
|
-
* @param handle - Native handle pointing to the memory
|
|
108
|
-
* @param type - Type of value to write
|
|
109
|
-
* @param offset - Byte offset from the handle pointer
|
|
110
|
-
* @param value - Value to write
|
|
111
|
-
*/
|
|
112
|
-
export function write(handle: NativeHandle, type: Type, offset: number, value: unknown): void {
|
|
113
|
-
native.write(handle, type, offset, value);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Allocates memory for a boxed type or plain struct.
|
|
118
|
-
*
|
|
119
|
-
* @param size - Size in bytes to allocate
|
|
120
|
-
* @param glibTypeName - GLib type name for boxed types (optional for plain structs)
|
|
121
|
-
* @param lib - Optional library containing the type
|
|
122
|
-
* @returns Native pointer to allocated memory
|
|
123
|
-
*/
|
|
124
|
-
export function alloc(size: number, glibTypeName?: string, lib?: string): NativeHandle {
|
|
125
|
-
return native.alloc(size, glibTypeName, lib) as NativeHandle;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Gets the internal handle ID for a native pointer.
|
|
130
|
-
*
|
|
131
|
-
* Used for comparing object identity.
|
|
132
|
-
*
|
|
133
|
-
* @param handle - Native handle
|
|
134
|
-
* @returns Internal handle ID
|
|
135
|
-
*/
|
|
136
|
-
export function getNativeId(handle: NativeHandle): number {
|
|
137
|
-
return native.getNativeId(handle);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function isNativeHandle(value: unknown): value is NativeHandle {
|
|
141
|
-
return native.isNativeHandle(value);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function freeze(): void {
|
|
145
|
-
native.freeze();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function unfreeze(): void {
|
|
149
|
-
native.unfreeze();
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export type { Arg, CallbackType, FfiValue, NativeHandle, Ref, Type };
|
package/types.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Opaque handle for a native value.
|
|
3
|
-
*
|
|
4
|
-
* Wraps GObject, Boxed, and Fundamental type instances.
|
|
5
|
-
* This branded type ensures type safety for native object references.
|
|
6
|
-
*/
|
|
7
|
-
export type NativeHandle = { readonly __brand: "NativeHandle" };
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Union of all possible FFI return value types.
|
|
11
|
-
*
|
|
12
|
-
* Returned by `call()` and `read()` where the concrete type
|
|
13
|
-
* depends on the type descriptor passed to the function.
|
|
14
|
-
*/
|
|
15
|
-
export type FfiValue = NativeHandle | number | string | boolean | FfiValue[] | null | undefined;
|
|
16
|
-
|
|
17
|
-
type Int8Type = { type: "int8" };
|
|
18
|
-
type Uint8Type = { type: "uint8" };
|
|
19
|
-
type Int16Type = { type: "int16" };
|
|
20
|
-
type Uint16Type = { type: "uint16" };
|
|
21
|
-
type Int32Type = { type: "int32" };
|
|
22
|
-
type Uint32Type = { type: "uint32" };
|
|
23
|
-
type Int64Type = { type: "int64" };
|
|
24
|
-
type Uint64Type = { type: "uint64" };
|
|
25
|
-
|
|
26
|
-
type Float32Type = { type: "float32" };
|
|
27
|
-
type Float64Type = { type: "float64" };
|
|
28
|
-
|
|
29
|
-
type EnumType = { type: "enum"; library: string; getTypeFn: string; signed: boolean };
|
|
30
|
-
type FlagsType = { type: "flags"; library: string; getTypeFn: string; signed: boolean };
|
|
31
|
-
|
|
32
|
-
type BooleanType = { type: "boolean" };
|
|
33
|
-
|
|
34
|
-
type Ownership = "full" | "borrowed";
|
|
35
|
-
|
|
36
|
-
type StringType = { type: "string"; ownership: Ownership; length?: number };
|
|
37
|
-
|
|
38
|
-
type GObjectType = { type: "gobject"; ownership: Ownership };
|
|
39
|
-
|
|
40
|
-
type BoxedType = { type: "boxed"; ownership: Ownership; innerType: string; library?: string; getTypeFn?: string };
|
|
41
|
-
|
|
42
|
-
type StructType = { type: "struct"; ownership: Ownership; innerType: string; size?: number };
|
|
43
|
-
|
|
44
|
-
type FundamentalType = {
|
|
45
|
-
type: "fundamental";
|
|
46
|
-
ownership: Ownership;
|
|
47
|
-
library: string;
|
|
48
|
-
refFn: string;
|
|
49
|
-
unrefFn: string;
|
|
50
|
-
typeName?: string;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
type ArrayType = {
|
|
54
|
-
type: "array";
|
|
55
|
-
itemType: Type;
|
|
56
|
-
kind: "array" | "glist" | "gslist" | "gptrarray" | "garray" | "gbytearray" | "sized" | "fixed";
|
|
57
|
-
ownership: Ownership;
|
|
58
|
-
elementSize?: number;
|
|
59
|
-
sizeParamIndex?: number;
|
|
60
|
-
fixedSize?: number;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
type HashTableType = {
|
|
64
|
-
type: "hashtable";
|
|
65
|
-
keyType: Type;
|
|
66
|
-
valueType: Type;
|
|
67
|
-
ownership: Ownership;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
type RefType = { type: "ref"; innerType: Type };
|
|
71
|
-
|
|
72
|
-
type UnicharType = { type: "unichar" };
|
|
73
|
-
|
|
74
|
-
type VoidType = { type: "void" };
|
|
75
|
-
|
|
76
|
-
export type CallbackType = {
|
|
77
|
-
type: "callback";
|
|
78
|
-
kind: "closure";
|
|
79
|
-
argTypes: Type[];
|
|
80
|
-
returnType: Type;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export type TrampolineType = {
|
|
84
|
-
type: "trampoline";
|
|
85
|
-
argTypes: Type[];
|
|
86
|
-
returnType: Type;
|
|
87
|
-
hasDestroy?: boolean;
|
|
88
|
-
userDataIndex?: number;
|
|
89
|
-
scope?: "call" | "notified" | "async" | "forever";
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Discriminated union of all FFI type descriptors.
|
|
94
|
-
*
|
|
95
|
-
* Describes how to marshal values between JavaScript and native code.
|
|
96
|
-
*/
|
|
97
|
-
export type Type =
|
|
98
|
-
| Int8Type
|
|
99
|
-
| Uint8Type
|
|
100
|
-
| Int16Type
|
|
101
|
-
| Uint16Type
|
|
102
|
-
| Int32Type
|
|
103
|
-
| Uint32Type
|
|
104
|
-
| Int64Type
|
|
105
|
-
| Uint64Type
|
|
106
|
-
| Float32Type
|
|
107
|
-
| Float64Type
|
|
108
|
-
| EnumType
|
|
109
|
-
| FlagsType
|
|
110
|
-
| BooleanType
|
|
111
|
-
| StringType
|
|
112
|
-
| GObjectType
|
|
113
|
-
| BoxedType
|
|
114
|
-
| StructType
|
|
115
|
-
| FundamentalType
|
|
116
|
-
| ArrayType
|
|
117
|
-
| HashTableType
|
|
118
|
-
| RefType
|
|
119
|
-
| CallbackType
|
|
120
|
-
| TrampolineType
|
|
121
|
-
| UnicharType
|
|
122
|
-
| VoidType;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* An argument for an FFI call.
|
|
126
|
-
*
|
|
127
|
-
* Combines a value with its type information for marshaling.
|
|
128
|
-
*/
|
|
129
|
-
export type Arg = {
|
|
130
|
-
/** Type descriptor for marshaling */
|
|
131
|
-
type: Type;
|
|
132
|
-
/** The argument value */
|
|
133
|
-
value: unknown;
|
|
134
|
-
/** Whether the argument can be null/undefined */
|
|
135
|
-
optional?: boolean;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* A mutable reference wrapper for out-parameters.
|
|
140
|
-
*
|
|
141
|
-
* @typeParam T - The type of the referenced value
|
|
142
|
-
*/
|
|
143
|
-
export type Ref<T> = {
|
|
144
|
-
readonly __brand: "Ref";
|
|
145
|
-
value: T;
|
|
146
|
-
};
|