Decorator factory for creating callables for native functions.

    Decorator factory for constructing relatively-nicely-looking callables that
    call into existing native functions exposed from a dynamically-linkable
    library.

    :param library:
        The library to look at
    :param name_or_ordinal:
        Typically the name of the symbol to load from the library.  In rare
        cases it may also be the index of the function inside the library.
    :param proto_factory:
        The prototype factory.
    :param use_last_error:
        Passed directly to the prototype factory.
    :param use_last_error:
        Passed directly to the prototype factory.
    :returns:
        A decorator for a function with particular, special annotations.

    .. note::
        Since nested functions have hard-to-reach documentation, the
        documentation of the function returned from ``native()`` is documented
        below.

def Function(
    library: CDLL,
    name_or_ordinal: 'Union[str, int, None]'=None,
    proto_factory: ('Union[ctypes.CFUNCTYPE, ctypes.WINFUNCTYPE,'
                    ' ctypes.PYFUNCTYPE]')=CFUNCTYPE,
    use_errno: bool=False,
    use_last_error: bool=False,
) -> 'Callable':
    """
    Decorator factory for creating callables for native functions.

    Decorator factory for constructing relatively-nicely-looking callables that
    call into existing native functions exposed from a dynamically-linkable
    library.

    :param library:
        The library to look at
    :param name_or_ordinal:
        Typically the name of the symbol to load from the library.  In rare
        cases it may also be the index of the function inside the library.
    :param proto_factory:
        The prototype factory.
    :param use_last_error:
        Passed directly to the prototype factory.
    :param use_last_error:
        Passed directly to the prototype factory.
    :returns:
        A decorator for a function with particular, special annotations.

    .. note::
        Since nested functions have hard-to-reach documentation, the
        documentation of the function returned from ``native()`` is documented
        below.
    """
    def decorator(fn: 'Callable') -> 'Callable':
        metadata = _ctypes_metadata(fn)
        prototype = proto_factory(
            metadata.restype, *metadata.argtypes,
            use_errno=use_errno, use_last_error=use_last_error)
        func_spec = (name_or_ordinal or fn.__name__, library)
        return prototype(func_spec, metadata.paramflags)
    return decorator