~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Lib/python/pyuserdir.swg

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-09-01 18:35:55 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050901183555-eq59uwhq8b62e44c
Tags: 1.3.24-1ubuntu4
* Use php5-dev instead of php4-dev, to kick php4 out of main.
* Drop support for generation of pike bindings, as nothing uses it,
  and swig is the only thing keeping pike7.6 in main (Ubuntu #13796)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -----------------------------------------------------------------------------
 
2
 *  Special user directives
 
3
 * ----------------------------------------------------------------------------- */
 
4
 
 
5
/* shadow code */
 
6
#define %shadow      %insert("shadow")
 
7
#define %pythoncode  %insert("python")
 
8
 
 
9
 
 
10
/* 
 
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.
 
13
 
 
14
For example, for the class
 
15
 
 
16
%pythonnondynamic(1) A;
 
17
struct A
 
18
{
 
19
  int a;
 
20
  int b;
 
21
};
 
22
 
 
23
you will get:
 
24
 
 
25
 aa = A()
 
26
 aa.a = 1  # Ok
 
27
 aa.b = 1  # Ok
 
28
 aa.c = 3  # error
 
29
 
 
30
Since "nondynamic" is a feature, if you use it like
 
31
 
 
32
%pythonnondynamic(1);
 
33
 
 
34
it will make all the wrapped classes nondynamic ones.
 
35
 
 
36
The implementation is based on the recipe:
 
37
 
 
38
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158
 
39
 
 
40
and works for modern (-modern) and plain python. We don't use __slots__, 
 
41
so, it works with old python versions. 
 
42
 
 
43
You can also use the raw %feature form
 
44
 
 
45
%feature("pythonnondynamic") A;
 
46
 
 
47
or the inverse form
 
48
 
 
49
%pythondynamic(0) A;
 
50
 
 
51
 
 
52
*/
 
53
 
 
54
 
 
55
#define %pythonnondynamic(FLAG) %feature("python:nondynamic", #FLAG)
 
56
#define %pythondynamic(FLAG) %pythonnondynamic(!FLAG)
 
57
 
 
58
 
 
59
/*
 
60
 
 
61
Use %pythonmaybecall to flag a method like __add__ or __radd__, which
 
62
don't produce an error when called, they just return NotImplemented.
 
63
 
 
64
These methods "may be called" if needed.
 
65
 
 
66
*/
 
67
 
 
68
%define %pythonmaybecall(FLAG) %feature("python:maybecall",#FLAG) %enddef
 
69
 
 
70
/*
 
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. 
 
74
 
 
75
  Just use it as
 
76
 
 
77
    %pythoncallback(1) foo;
 
78
    int foo(int a);
 
79
 
 
80
    %pythoncallback(1) A::foo;
 
81
    struct A {
 
82
     static int foo(int a);
 
83
    };
 
84
 
 
85
    int bar(int, int (*pf)(int));
 
86
 
 
87
  then, you can use it as:
 
88
 
 
89
   a = foo(1)
 
90
   b = bar(2, foo)
 
91
 
 
92
   c = A.foo(3)
 
93
   d = bar(4, A.foo)
 
94
 
 
95
 
 
96
   If you use it with a member method
 
97
   %pythoncallback(1) A::foom;
 
98
   struct A {
 
99
      int foom(int a);
 
100
   };
 
101
 
 
102
   then you can use it as
 
103
 
 
104
     r = a.foom(3)             # eval the method
 
105
     mptr = A.foom_cb_ptr      # returns the callback pointer
 
106
 
 
107
   where the '_cb_ptr' termination is added for the callback pointer.
 
108
 
 
109
*/
 
110
 
 
111
#define %pythoncallback(x) %feature("python:callback",`x`)
 
112
#define %nopythoncallback %feature("python:callback","")
 
113
 
 
114
/*  Support for the old %callback directive name */
 
115
#ifdef %callback
 
116
#undef %callback
 
117
#endif
 
118
#define %callback(x) %pythoncallback(x)
 
119
 
 
120
#ifdef %nocallback
 
121
#undef %nocallback
 
122
#endif
 
123
#define %nocallback %nopythoncallback; %feature("callback","")
 
124