@gtkx/gir 0.9.0 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/gir",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "GObject Introspection file parser for GTKX",
5
5
  "keywords": [
6
6
  "gtk",
package/src/parser.ts CHANGED
@@ -186,18 +186,22 @@ export class GirParser {
186
186
  }
187
187
  return methods
188
188
  .filter((method) => method["@_introspectable"] !== "0")
189
- .map((method) => ({
190
- name: String(method["@_name"] ?? ""),
191
- cIdentifier: String(method["@_c:identifier"] ?? ""),
192
- returnType: this.parseReturnType(method["return-value"] as Record<string, unknown> | undefined),
193
- parameters: this.parseParameters(
194
- (method.parameters && typeof method.parameters === "object" && method.parameters !== null
195
- ? method.parameters
196
- : {}) as Record<string, unknown>,
197
- ),
198
- throws: method["@_throws"] === "1",
199
- doc: extractDoc(method),
200
- }));
189
+ .map((method) => {
190
+ const returnValue = method["return-value"] as Record<string, unknown> | undefined;
191
+ return {
192
+ name: String(method["@_name"] ?? ""),
193
+ cIdentifier: String(method["@_c:identifier"] ?? ""),
194
+ returnType: this.parseReturnType(returnValue),
195
+ parameters: this.parseParameters(
196
+ (method.parameters && typeof method.parameters === "object" && method.parameters !== null
197
+ ? method.parameters
198
+ : {}) as Record<string, unknown>,
199
+ ),
200
+ throws: method["@_throws"] === "1",
201
+ doc: extractDoc(method),
202
+ returnDoc: returnValue ? extractDoc(returnValue) : undefined,
203
+ };
204
+ });
201
205
  }
202
206
 
203
207
  private parseConstructors(constructors: Record<string, unknown>[]): GirConstructor[] {
@@ -206,18 +210,22 @@ export class GirParser {
206
210
  }
207
211
  return constructors
208
212
  .filter((ctor) => ctor["@_introspectable"] !== "0")
209
- .map((ctor) => ({
210
- name: String(ctor["@_name"] ?? ""),
211
- cIdentifier: String(ctor["@_c:identifier"] ?? ""),
212
- returnType: this.parseReturnType(ctor["return-value"] as Record<string, unknown> | undefined),
213
- parameters: this.parseParameters(
214
- (ctor.parameters && typeof ctor.parameters === "object" && ctor.parameters !== null
215
- ? ctor.parameters
216
- : {}) as Record<string, unknown>,
217
- ),
218
- throws: ctor["@_throws"] === "1",
219
- doc: extractDoc(ctor),
220
- }));
213
+ .map((ctor) => {
214
+ const returnValue = ctor["return-value"] as Record<string, unknown> | undefined;
215
+ return {
216
+ name: String(ctor["@_name"] ?? ""),
217
+ cIdentifier: String(ctor["@_c:identifier"] ?? ""),
218
+ returnType: this.parseReturnType(returnValue),
219
+ parameters: this.parseParameters(
220
+ (ctor.parameters && typeof ctor.parameters === "object" && ctor.parameters !== null
221
+ ? ctor.parameters
222
+ : {}) as Record<string, unknown>,
223
+ ),
224
+ throws: ctor["@_throws"] === "1",
225
+ doc: extractDoc(ctor),
226
+ returnDoc: returnValue ? extractDoc(returnValue) : undefined,
227
+ };
228
+ });
221
229
  }
222
230
 
223
231
  private parseFunctions(functions: Record<string, unknown>[]): GirFunction[] {
@@ -226,18 +234,22 @@ export class GirParser {
226
234
  }
227
235
  return functions
228
236
  .filter((func) => func["@_introspectable"] !== "0")
229
- .map((func) => ({
230
- name: String(func["@_name"] ?? ""),
231
- cIdentifier: String(func["@_c:identifier"] ?? ""),
232
- returnType: this.parseReturnType(func["return-value"] as Record<string, unknown> | undefined),
233
- parameters: this.parseParameters(
234
- (func.parameters && typeof func.parameters === "object" && func.parameters !== null
235
- ? func.parameters
236
- : {}) as Record<string, unknown>,
237
- ),
238
- throws: func["@_throws"] === "1",
239
- doc: extractDoc(func),
240
- }));
237
+ .map((func) => {
238
+ const returnValue = func["return-value"] as Record<string, unknown> | undefined;
239
+ return {
240
+ name: String(func["@_name"] ?? ""),
241
+ cIdentifier: String(func["@_c:identifier"] ?? ""),
242
+ returnType: this.parseReturnType(returnValue),
243
+ parameters: this.parseParameters(
244
+ (func.parameters && typeof func.parameters === "object" && func.parameters !== null
245
+ ? func.parameters
246
+ : {}) as Record<string, unknown>,
247
+ ),
248
+ throws: func["@_throws"] === "1",
249
+ doc: extractDoc(func),
250
+ returnDoc: returnValue ? extractDoc(returnValue) : undefined,
251
+ };
252
+ });
241
253
  }
242
254
 
243
255
  private parseParameters(parametersNode: Record<string, unknown>): GirParameter[] {
package/src/types.ts CHANGED
@@ -178,6 +178,8 @@ export type GirMethod = {
178
178
  throws?: boolean;
179
179
  /** Documentation for the method. */
180
180
  doc?: string;
181
+ /** Documentation for the return value. */
182
+ returnDoc?: string;
181
183
  };
182
184
 
183
185
  /**
@@ -196,6 +198,8 @@ export type GirConstructor = {
196
198
  throws?: boolean;
197
199
  /** Documentation for the constructor. */
198
200
  doc?: string;
201
+ /** Documentation for the return value. */
202
+ returnDoc?: string;
199
203
  };
200
204
 
201
205
  /**
@@ -214,6 +218,8 @@ export type GirFunction = {
214
218
  throws?: boolean;
215
219
  /** Documentation for the function. */
216
220
  doc?: string;
221
+ /** Documentation for the return value. */
222
+ returnDoc?: string;
217
223
  };
218
224
 
219
225
  /**
@@ -344,6 +350,10 @@ export type FfiTypeDescriptor = {
344
350
  borrowed?: boolean;
345
351
  /** Inner type for ref types (as descriptor) or boxed types (as GLib type name string). */
346
352
  innerType?: FfiTypeDescriptor | string;
353
+ /** Library name for boxed types that need dynamic type lookup. */
354
+ lib?: string;
355
+ /** Explicit get_type function name for boxed types (when naive transformation doesn't work). */
356
+ getTypeFn?: string;
347
357
  /** Item type for array types. */
348
358
  itemType?: FfiTypeDescriptor;
349
359
  /** List type for arrays (glist, gslist) - indicates native GList/GSList iteration. */
@@ -441,7 +451,7 @@ export class TypeRegistry {
441
451
  * @param namespace - The namespace containing the class
442
452
  * @param name - The class name
443
453
  */
444
- registerType(namespace: string, name: string): void {
454
+ registerNativeClass(namespace: string, name: string): void {
445
455
  const transformedName = normalizeTypeName(name, namespace);
446
456
  this.types.set(`${namespace}.${name}`, {
447
457
  kind: "class",
@@ -557,7 +567,7 @@ export class TypeRegistry {
557
567
  const registry = new TypeRegistry();
558
568
  for (const ns of namespaces) {
559
569
  for (const cls of ns.classes) {
560
- registry.registerType(ns.name, cls.name);
570
+ registry.registerNativeClass(ns.name, cls.name);
561
571
  }
562
572
  for (const iface of ns.interfaces) {
563
573
  registry.registerInterface(ns.name, iface.name);
@@ -1195,7 +1205,13 @@ export class TypeMapper {
1195
1205
  trampoline: "drawFunc",
1196
1206
  argTypes: [
1197
1207
  { type: "gobject", borrowed: true },
1198
- { type: "boxed", borrowed: true, innerType: "CairoContext" },
1208
+ {
1209
+ type: "boxed",
1210
+ borrowed: true,
1211
+ innerType: "CairoContext",
1212
+ lib: "libcairo-gobject.so.2",
1213
+ getTypeFn: "cairo_gobject_context_get_type",
1214
+ },
1199
1215
  { type: "int", size: 32, unsigned: false },
1200
1216
  { type: "int", size: 32, unsigned: false },
1201
1217
  ],