Skip to main content

Function: getNativeObject()

getNativeObject<T, TClass>(handle, targetType?): GetNativeObjectResult<T, TClass>

Defined in: packages/ffi/src/native/object.ts:34

Creates a JavaScript wrapper for a native GObject.

Resolves the runtime type of the object and creates an instance of the appropriate wrapper class. If a target type is provided, uses that class directly without runtime type resolution.

Type Parameters

Type ParameterDefault typeDescription
T extends NativeHandle | null | undefined-The handle type (null, undefined, or NativeHandle)
TClass extends NativeClass | undefinedundefinedOptional target wrapper class type

Parameters

ParameterTypeDescription
handleTThe native handle (or null/undefined)
targetType?TClassOptional wrapper class to use directly

Returns

GetNativeObjectResult<T, TClass>

A wrapper instance, or null if handle is null/undefined

Example

// Automatic type resolution
const widget = getNativeObject(widgetHandle);

// Explicit type
const button = getNativeObject(buttonHandle, Gtk.Button);