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

« back to all changes in this revision

Viewing changes to Doc/Manual/SWIG.html

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2006-12-20 14:43:24 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061220144324-bps3kb06xp5oy9w1
Tags: 1.3.31-1ubuntu1
* Merge from debian unstable, remaining changes:
  - drop support for pike
  - use php5 instead of php4
  - clean Runtime/ as well
  - force a few environment variables

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
<li><a href="#SWIG_structure_data_members">Structure data members</a>
56
56
<li><a href="#SWIG_nn36">C constructors and destructors </a>
57
57
<li><a href="#SWIG_adding_member_functions">Adding member functions to C structures</a>
58
 
<li><a href="#SWIG_nn38">Nested structures</a>
 
58
<li><a href="#SWIG_nested_structs">Nested structures</a>
59
59
<li><a href="#SWIG_nn39">Other things to note about structure wrapping</a>
60
60
</ul>
61
61
<li><a href="#SWIG_nn40">Code Insertion</a>
1701
1701
</div>
1702
1702
 
1703
1703
<p>
1704
 
One use of <tt>%ignore</tt> is to selectively remove certain declarations from a header file without having
 
1704
Any function, variable etc which matches <tt>%ignore</tt> will not be wrapped and therefore will not be available from the target language.
 
1705
A common usage of <tt>%ignore</tt> is to selectively remove certain declarations from a header file without having
1705
1706
to add conditional compilation to the header.   However, it should be stressed that this only works for simple
1706
1707
declarations.  If you need to remove a whole section of problematic code, the SWIG preprocessor should be used instead.
1707
1708
</p>
1830
1831
</div>
1831
1832
 
1832
1833
<p>
1833
 
Unfortunately, by declaring the callback functions as constants, they are no longer accesible
 
1834
Unfortunately, by declaring the callback functions as constants, they are no longer accessible
1834
1835
as functions. For example:
1835
1836
</p>
1836
1837
 
2335
2336
</pre></div>
2336
2337
 
2337
2338
<p>
2338
 
You can make a <tt>Vector</tt> look alot like a class by writing a SWIG interface like this:
 
2339
You can make a <tt>Vector</tt> look a lot like a class by writing a SWIG interface like this:
2339
2340
</p>
2340
2341
 
2341
2342
<div class="code"><pre>
2356
2357
                return v;
2357
2358
        }
2358
2359
        ~Vector() {
2359
 
                free(self);
 
2360
                free($self);
2360
2361
        }
2361
2362
        double magnitude() {
2362
 
                return sqrt(self-&gt;x*self-&gt;x+self-&gt;y*self-&gt;y+self-&gt;z*self-&gt;z);
 
2363
                return sqrt($self-&gt;x*$self-&gt;x+$self-&gt;y*$self-&gt;y+$self-&gt;z*$self-&gt;z);
2363
2364
        }
2364
2365
        void print() {
2365
 
                printf("Vector [%g, %g, %g]\n", self-&gt;x,self-&gt;y,self-&gt;z);
 
2366
                printf("Vector [%g, %g, %g]\n", $self-&gt;x,$self-&gt;y,$self-&gt;z);
2366
2367
        }
2367
2368
};
2368
2369
 
2369
2370
</pre></div>
2370
2371
 
2371
2372
<p>
 
2373
Note the usage of the <tt>$self</tt> special variable.
 
2374
Its usage is identical to a C++ 'this' pointer and should be used whenever access to the struct instance is required.
 
2375
</p>
 
2376
 
 
2377
<p>
2372
2378
Now, when used with proxy classes in Python, you can do things like
2373
2379
this :</p>
2374
2380
 
2471
2477
</div>
2472
2478
 
2473
2479
<p>
2474
 
Now, for all practial purposes, <tt>magnitude</tt> will appear like an attribute
 
2480
Now, for all practical purposes, <tt>magnitude</tt> will appear like an attribute
2475
2481
of the object.
2476
2482
</p>
2477
2483
 
2530
2536
directive name has been chosen.
2531
2537
</p>
2532
2538
 
2533
 
<H3><a name="SWIG_nn38"></a>5.5.7 Nested structures</H3>
 
2539
<H3><a name="SWIG_nested_structs"></a>5.5.7 Nested structures</H3>
2534
2540
 
2535
2541
 
2536
2542
<p>
2940
2946
<ul>
2941
2947
<li>It is rarely necessary to access every single function in a large
2942
2948
package. Many C functions might have little or no use in a scripted
2943
 
environment. Therfore, why wrap them?
 
2949
environment. Therefore, why wrap them?
2944
2950
 
2945
2951
<li>Separate interface files provide an opportunity to provide more
2946
2952
precise rules about how an interface is to be constructed.