1
/* -----------------------------------------------------------------------------
2
* Special user directives
3
* ----------------------------------------------------------------------------- */
6
#define %shadow %insert("shadow")
7
#define %pythoncode %insert("python")
11
Use the "nondynamic" feature to make a wrapped class behaves as a "nondynamic"
12
one, ie, a python class that doesn't dynamically add new attributes.
14
For example, for the class
16
%pythonnondynamic(1) A;
30
Since "nondynamic" is a feature, if you use it like
34
it will make all the wrapped classes nondynamic ones.
36
The implementation is based on the recipe:
38
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158
40
and works for modern (-modern) and plain python. We don't use __slots__,
41
so, it works with old python versions.
43
You can also use the raw %feature form
45
%feature("pythonnondynamic") A;
55
#define %pythonnondynamic(FLAG) %feature("python:nondynamic", #FLAG)
56
#define %pythondynamic(FLAG) %pythonnondynamic(!FLAG)
61
Use %pythonmaybecall to flag a method like __add__ or __radd__, which
62
don't produce an error when called, they just return NotImplemented.
64
These methods "may be called" if needed.
68
%define %pythonmaybecall(FLAG) %feature("python:maybecall",#FLAG) %enddef
71
The %pythoncallback feature produce a more natural callback wrap
72
than the %callback mechanism, ie, it use the original name for
73
the callback and callable objects.
77
%pythoncallback(1) foo;
80
%pythoncallback(1) A::foo;
82
static int foo(int a);
85
int bar(int, int (*pf)(int));
87
then, you can use it as:
96
If you use it with a member method
97
%pythoncallback(1) A::foom;
102
then you can use it as
104
r = a.foom(3) # eval the method
105
mptr = A.foom_cb_ptr # returns the callback pointer
107
where the '_cb_ptr' termination is added for the callback pointer.
111
#define %pythoncallback(x) %feature("python:callback",`x`)
112
#define %nopythoncallback %feature("python:callback","")
114
/* Support for the old %callback directive name */
118
#define %callback(x) %pythoncallback(x)
123
#define %nocallback %nopythoncallback; %feature("callback","")