Skip to content

Commit

Permalink
correctly set interface vfuncs
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien committed Jan 6, 2024
1 parent fba7b93 commit a123e2b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/bindings/girepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const { g } = openLib(libName("girepository-1.0", 1), {
get_vfunc: $pointer($pointer, $i32),
get_n_properties: $i32($pointer),
get_property: $pointer($pointer, $i32),
get_iface_struct: $pointer($pointer),
},
property_info: {
get_flags: $i32($pointer),
Expand Down
11 changes: 11 additions & 0 deletions src/bindings/gobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ const { g } = openLib(libName("gobject-2.0", 0), {
get_object: $pointer($buffer),
get_boxed: $pointer($buffer),
},
closure: {
new_simple: $pointer($u32, $pointer),
set_marshal: $void($pointer, $pointer),
ref: $void($pointer),
sink: $void($pointer),
add_finalize_notifier: $void($pointer, $pointer, $pointer),
invoke: $void($pointer, $pointer, $u32, $pointer, $pointer),
},
cclosure: {
new: $pointer($pointer, $pointer, $pointer),
},
},
});

Expand Down
34 changes: 25 additions & 9 deletions src/types/callable.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,40 @@ export function handleCallable(target, info) {
set(value) {
const baseName = g.base_info.get_name(info);

const objectInfo = g.base_info.get_container(info);
const classStruct = g.object_info.get_class_struct(objectInfo);
const fieldInfo = g.struct_info.find_field(classStruct, baseName);
const containerInfo = g.base_info.get_container(info);
const containerType = g.base_info.get_type(containerInfo);

let containerStruct, pointer;

if (containerType === GIInfoType.INTERFACE) {
containerStruct = g.interface_info.get_iface_struct(containerInfo);
const klass = g.type_class.ref(
Reflect.getOwnMetadata("gi:gtype", this.constructor),
);
pointer = g.type_interface.peek(
klass,
g.registered_type_info.get_g_type(containerInfo),
);
} else {
// it's a class
containerStruct = g.object_info.get_class_struct(containerInfo);
pointer = g.type_class.ref(
Reflect.getOwnMetadata("gi:gtype", this.constructor),
);
}

const fieldInfo = g.struct_info.find_field(containerStruct, baseName);

if (!fieldInfo) {
// This vfunc doesn't have a corresponding field in the class struct
return;
}

const klass = g.type_class.ref(
Reflect.getOwnMetadata("gi:gtype", this.constructor),
);

const cb = createCallback(info, value);
const cb = createCallback(info, value, this);
const offset = g.field_info.get_offset(fieldInfo);
const dataView = new ExtendedDataView(
deref_buf(
klass,
pointer,
offset + 8,
offset,
),
Expand Down

0 comments on commit a123e2b

Please sign in to comment.