import { NobjcNative } from "./native.js";
declare class NobjcLibrary {
    [key: string]: NobjcObject;
    constructor(library: string);
}
declare class NobjcObject {
    [key: string]: NobjcMethod;
    constructor(object: NobjcNative.ObjcObject);
}
export interface TypedBlockOptions {
    /**
     * Block return type encoding. Example: "v" (void), "@" (id), "B" (BOOL).
     */
    returns: string;
    /**
     * Block argument type encodings, excluding the implicit block-self (@?) parameter.
     * Example: ["@", "Q", "^B"] for enumerateObjectsUsingBlock:.
     */
    args?: string[];
    /**
     * Full block type encoding. Example: "@?<v@?@Q^B>".
     * When provided, this takes precedence over returns/args.
     */
    types?: string;
}
/**
 * Attach an explicit block signature to a JavaScript function.
 *
 * Use this when Objective-C only exposes `@?` for a block parameter and
 * objc-js would otherwise have to guess the callback argument types.
 *
 * @example
 * ```typescript
 * const handler = typedBlock({ returns: "v", args: ["@", "Q", "^B"] }, (obj, idx, stop) => {
 *   console.log(obj.toString(), idx, stop);
 * });
 * array.enumerateObjectsUsingBlock$(handler);
 * ```
 */
declare function typedBlock<T extends (...args: any[]) => any>(signature: string | TypedBlockOptions, fn: T): T;
interface NobjcMethod {
    (...args: any[]): any;
}
declare const NobjcMethod: (object: NobjcNative.ObjcObject, methodName: string) => NobjcMethod;
declare class NobjcProtocol {
    static implement(protocolName: string, methodImplementations: Record<string, (...args: any[]) => any>): NobjcObject;
}
/**
 * Get the raw native pointer for a NobjcObject as a Node Buffer.
 * The pointer is stored in little-endian format (8 bytes on 64-bit macOS).
 *
 * @param obj - The NobjcObject to get the pointer from
 * @returns A Buffer containing the pointer address
 *
 * @example
 * ```typescript
 * const view = window.contentView();
 * const pointerBuffer = getPointer(view);
 * const pointer = pointerBuffer.readBigUInt64LE(0);
 * console.log(`NSView pointer: 0x${pointer.toString(16)}`);
 * ```
 */
declare function getPointer(obj: NobjcObject): Buffer;
/**
 * Create a NobjcObject from a raw native pointer.
 *
 * @param pointer - A Buffer or BigInt containing the pointer address
 * @returns A NobjcObject wrapping the native object
 *
 * @example
 * ```typescript
 * // From a Buffer
 * const pointerBuffer = getPointer(originalObject);
 * const reconstructed = fromPointer(pointerBuffer);
 *
 * // From a BigInt
 * const pointer = 0x12345678n;
 * const obj = fromPointer(pointer);
 *
 * // Round-trip example
 * const original = NSString.stringWithUTF8String$("Hello");
 * const ptr = getPointer(original).readBigUInt64LE(0);
 * const restored = fromPointer(ptr);
 * console.log(restored.toString()); // "Hello"
 * ```
 *
 * @warning This is unsafe! The pointer must point to a valid Objective-C object.
 * Using an invalid pointer will cause a crash. The object must still be alive
 * (not deallocated) when you call this function.
 */
declare function fromPointer(pointer: Buffer | bigint): NobjcObject;
/**
 * Method definition for defining a class method.
 */
interface MethodDefinition {
    /**
     * Objective-C type encoding string.
     * Common encodings:
     * - @ = id (object)
     * - : = SEL (selector)
     * - v = void
     * - B = BOOL
     * - q = long long / NSInteger (64-bit)
     * - Q = unsigned long long / NSUInteger (64-bit)
     * - ^@ = id* (pointer to object, e.g., NSError**)
     * - @? = block
     *
     * Example: "@@:@^@" means:
     * - Return: @ (id)
     * - self: @ (id)
     * - _cmd: : (SEL)
     * - arg1: @ (NSArray*)
     * - arg2: ^@ (NSError**)
     */
    types: string;
    /**
     * The JavaScript implementation.
     * Receives (self, ...args) where self is the instance.
     * For NSError** out-params, the arg is an object with { set(error), get() } methods.
     */
    implementation: (self: NobjcObject, ...args: any[]) => any;
}
/**
 * Class definition for creating a new Objective-C class.
 */
interface ClassDefinition {
    /** Name of the new Objective-C class (must be unique in the runtime) */
    name: string;
    /** Superclass - either a class name string or a NobjcObject representing a Class */
    superclass: string | NobjcObject;
    /** Optional: protocols to conform to */
    protocols?: string[];
    /** Instance methods to implement/override */
    methods?: Record<string, MethodDefinition>;
    /** Optional: class methods */
    classMethods?: Record<string, MethodDefinition>;
}
/**
 * API for defining new Objective-C classes at runtime.
 *
 * @example
 * ```typescript
 * // Define a subclass of NSObject
 * const MyClass = NobjcClass.define({
 *   name: "MyClass",
 *   superclass: "NSObject",
 *   protocols: ["NSCopying"],
 *   methods: {
 *     "init": {
 *       types: "@@:",
 *       implementation: (self) => {
 *         return NobjcClass.super(self, "init");
 *       }
 *     },
 *     "myMethod:": {
 *       types: "@@:@",
 *       implementation: (self, arg) => {
 *         console.log("myMethod called with", arg);
 *         return arg;
 *       }
 *     }
 *   }
 * });
 *
 * // Create an instance
 * const instance = MyClass.alloc().init();
 * instance.myMethod$(someArg);
 * ```
 */
declare class NobjcClass {
    /**
     * Define a new Objective-C class at runtime.
     *
     * @param definition The class definition
     * @returns A NobjcObject representing the new Class (can be used to alloc/init instances)
     *
     * @warning For private methods (like _requestContextWithRequests:error:), you must provide
     * the correct type encoding manually since it cannot be introspected from protocols.
     */
    static define(definition: ClassDefinition): NobjcObject;
    /**
     * Call the superclass implementation of a method.
     * Use this inside a method implementation to invoke super.
     *
     * @param self The instance (the first argument to your implementation)
     * @param selector The selector string (e.g., "init" or "_requestContextWithRequests:error:")
     * @param args Additional arguments to pass to super
     * @returns The result of the super call
     *
     * @example
     * ```typescript
     * methods: {
     *   "init": {
     *     types: "@@:",
     *     implementation: (self) => {
     *       // Call [super init]
     *       const result = NobjcClass.super(self, "init");
     *       // Do additional setup...
     *       return result;
     *     }
     *   }
     * }
     * ```
     */
    static super(self: NobjcObject, selector: string, ...args: any[]): any;
}
/**
 * Call a C function by name.
 *
 * The framework containing the function must be loaded first (e.g., via `new NobjcLibrary(...)`).
 * Uses `dlsym` to look up the function symbol and `libffi` to call it with the correct ABI.
 *
 * Argument types are inferred from JS values by default:
 * - NobjcObject → `@` (id)
 * - string → `@` (auto-converted to NSString)
 * - boolean → `B` (BOOL)
 * - number → `d` (double/CGFloat)
 * - null → `@` (nil)
 *
 * Return type defaults to `"v"` (void). Pass an options object to specify return/arg types.
 *
 * @param name - The function name (e.g., "NSLog", "NSHomeDirectory")
 * @param optionsOrFirstArg - Either a CallFunctionOptions object or the first function argument
 * @param args - The actual arguments to pass to the function
 * @returns The return value converted to a JavaScript type, or undefined for void functions
 *
 * @example
 * ```typescript
 * import { NobjcLibrary, callFunction } from "objc-js";
 *
 * const Foundation = new NobjcLibrary(
 *   "/System/Library/Frameworks/Foundation.framework/Foundation"
 * );
 * const NSString = Foundation.NSString;
 *
 * // Void function — simplest form, no options needed
 * const msg = NSString.stringWithUTF8String$("Hello!");
 * callFunction("NSLog", msg);
 *
 * // Function that returns a value — specify { returns }
 * const homeDir = callFunction("NSHomeDirectory", { returns: "@" });
 * console.log(homeDir.toString());
 *
 * // Explicit arg types when inference isn't enough
 * const selName = callFunction("NSStringFromSelector", { returns: "@", args: [":"] }, "description");
 *
 * // Combined type string shorthand (return + args)
 * const className = callFunction("NSStringFromClass", { types: "@#" }, NSString);
 * ```
 */
declare function callFunction(name: string, ...rest: any[]): any;
/**
 * Call a variadic C function by name.
 *
 * Correctly handles variadic calling conventions (important on Apple Silicon / ARM64
 * where variadic args go on the stack while fixed args go in registers).
 *
 * @param name - The function name (e.g., "NSLog")
 * @param optionsOrFixedCount - Either a CallFunctionOptions object or the fixedArgCount directly
 * @param fixedArgCountOrFirstArg - Number of fixed (non-variadic) arguments, or first arg if options were provided
 * @param args - The actual arguments to pass to the function
 * @returns The return value converted to a JavaScript type
 *
 * @example
 * ```typescript
 * import { NobjcLibrary, callVariadicFunction } from "objc-js";
 *
 * const Foundation = new NobjcLibrary(
 *   "/System/Library/Frameworks/Foundation.framework/Foundation"
 * );
 * const NSString = Foundation.NSString;
 *
 * // Simplest: void return, inferred args, fixedArgCount = 1
 * const format = NSString.stringWithUTF8String$("Hello, %@!");
 * const name = NSString.stringWithUTF8String$("World");
 * callVariadicFunction("NSLog", 1, format, name);
 *
 * // With explicit types
 * callVariadicFunction("NSLog", { returns: "v", args: ["@", "i"] }, 1, format, 42);
 * ```
 */
declare function callVariadicFunction(name: string, ...rest: any[]): any;
/**
 * Utilities for pumping the macOS CFRunLoop from a Node.js/Bun event loop.
 *
 * Required for async Objective-C callbacks (completion handlers, AppKit events, etc.)
 * to be delivered, since Node.js/Bun don't automatically pump the CFRunLoop.
 *
 * Usage:
 *   RunLoop.run();   // Start pumping (returns a cleanup function)
 *   RunLoop.pump();  // Pump once (non-blocking)
 */
declare const RunLoop: {
    _timer: ReturnType<typeof setInterval> | null;
    _mainRunLoop: any;
    _defaultMode: any;
    _NSDate: any;
    /**
     * Lazily initialise NSRunLoop and NSDefaultRunLoopMode references.
     * Foundation is already loaded by the time any ObjC work happens, so
     * GetClassObject will succeed without an explicit LoadLibrary call.
     *
     * We use proxy-wrapped NobjcObjects (via wrapObjCObjectIfNeeded) rather
     * than raw native ObjcObjects + $msgSend, because Bun's N-API crashes
     * when CFRunLoopRunInMode is triggered from the $msgSend C++ path.
     * The proxy path ($prepareSend + $msgSendPrepared) works on both runtimes.
     */
    _ensureRunLoop(): void;
    /**
     * Pump the run loop once. Processes any pending run loop sources
     * (AppKit events, dispatch_async to main queue, timers, etc.)
     * without blocking.
     *
     * @param timeout Optional timeout in seconds (default: 0)
     * @returns true if a source was processed
     */
    pump(timeout?: number): boolean;
    /**
     * Start continuously pumping the run loop on a regular interval.
     * This enables async Objective-C callbacks to be delivered.
     *
     * @param intervalMs Pump interval in milliseconds (default: 10)
     * @returns A cleanup function that stops pumping
     */
    run(intervalMs?: number): () => void;
    /**
     * Stop pumping the run loop.
     */
    stop(): void;
};
export { NobjcLibrary, NobjcObject, NobjcMethod, NobjcProtocol, NobjcClass, typedBlock, RunLoop, getPointer, fromPointer, callFunction, callVariadicFunction };
