@@ -1025,6 +1025,22 @@ As we can easily check, our array is sorted now::
1025
1025
1 5 7 33 99
1026
1026
>>>
1027
1027
1028
+ The function factories can be used as decorator factories, so we may as well
1029
+ write::
1030
+
1031
+ >>> @CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))
1032
+ ... def py_cmp_func(a, b):
1033
+ ... print("py_cmp_func", a[0], b[0])
1034
+ ... return a[0] - b[0]
1035
+ ...
1036
+ >>> qsort(ia, len(ia), sizeof(c_int), py_cmp_func)
1037
+ py_cmp_func 5 1
1038
+ py_cmp_func 33 99
1039
+ py_cmp_func 7 33
1040
+ py_cmp_func 1 7
1041
+ py_cmp_func 5 7
1042
+ >>>
1043
+
1028
1044
.. note ::
1029
1045
1030
1046
Make sure you keep references to :func: `CFUNCTYPE ` objects as long as they
@@ -1577,7 +1593,9 @@ Foreign functions can also be created by instantiating function prototypes.
1577
1593
Function prototypes are similar to function prototypes in C; they describe a
1578
1594
function (return type, argument types, calling convention) without defining an
1579
1595
implementation. The factory functions must be called with the desired result
1580
- type and the argument types of the function.
1596
+ type and the argument types of the function, and can be used as decorator
1597
+ factories, and as such, be applied to functions through the ``@wrapper `` syntax.
1598
+ See :ref: `ctypes-callback-functions ` for examples.
1581
1599
1582
1600
1583
1601
.. function :: CFUNCTYPE(restype, *argtypes, use_errno=False, use_last_error=False)
0 commit comments