Various and sundry updates for the Pike module.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4758 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d257f78b08
commit
840719b9ee
6 changed files with 147 additions and 59 deletions
|
|
@ -1,13 +1,33 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>SWIG and Pike</title>
|
||||
<meta http-equiv="content-type"
|
||||
content="text/html; charset=ISO-8859-1">
|
||||
<title>SWIG and Pike</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>SWIG and Pike<br>
|
||||
</h1>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<a name="n1"></a><H1>5 SWIG and Pike</H1>
|
||||
<!-- INDEX -->
|
||||
<ul>
|
||||
<li><a href="#n2">Preliminaries</a>
|
||||
<ul>
|
||||
<li><a href="#n3">Running SWIG</a>
|
||||
<li><a href="#n4">Getting the right header files</a>
|
||||
<li><a href="#n5">Using your module</a>
|
||||
</ul>
|
||||
<li><a href="#n6">Basic C/C++ Mapping</a>
|
||||
<ul>
|
||||
<li><a href="#n7">Modules</a>
|
||||
<li><a href="#n8">Functions</a>
|
||||
<li><a href="#n9">Global variables</a>
|
||||
<li><a href="#n10">Constants and enumerated types</a>
|
||||
<li><a href="#n11">Constructors and Destructors</a>
|
||||
<li><a href="#n12">Static Members</a>
|
||||
</ul>
|
||||
</ul>
|
||||
<!-- INDEX -->
|
||||
|
||||
|
||||
|
||||
This chapter describes SWIG support for Pike. As of this writing, the
|
||||
SWIG Pike module is still under development and is not considered
|
||||
ready for prime time. The Pike module is being developed against the
|
||||
|
|
@ -19,8 +39,12 @@ are covered in less depth than in earlier chapters. At the very
|
|||
least, make sure you read the "<a
|
||||
href="file:///home/jlj/src/SWIG/Doc/Manual/SWIG.html">SWIG Basics</a>"
|
||||
chapter.<br>
|
||||
<h2>Preliminaries</h2>
|
||||
<h3>Running SWIG</h3>
|
||||
<a name="n2"></a><H2>5.1 Preliminaries</H2>
|
||||
|
||||
|
||||
<a name="n3"></a><H3>5.1.1 Running SWIG</H3>
|
||||
|
||||
|
||||
Suppose that you defined a SWIG module such as the following:
|
||||
<blockquote>
|
||||
<pre>%module example<br><br>%{<br>#include "example.h"<br>%}<br><br>int fact(int n);<br></pre>
|
||||
|
|
@ -46,7 +70,9 @@ can use the <tt>-o</tt> option:
|
|||
<blockquote>
|
||||
<pre>$ <b>swig -pike -o pseudonym.c example.i</b><br></pre>
|
||||
</blockquote>
|
||||
<h3>Getting the right header files</h3>
|
||||
<a name="n4"></a><H3>5.1.2 Getting the right header files</H3>
|
||||
|
||||
|
||||
In order to compile the C/C++ wrappers, the compiler needs to know the
|
||||
path to the Pike header files. These files are usually contained in a
|
||||
directory such as
|
||||
|
|
@ -59,7 +85,9 @@ location of these files, so you may need to hunt around for them.
|
|||
You're looking for files with the names <tt>global.h</tt>, <tt>program.h</tt>
|
||||
and so on.
|
||||
|
||||
<h3>Using your module</h3>
|
||||
<a name="n5"></a><H3>5.1.3 Using your module</H3>
|
||||
|
||||
|
||||
To use your module, simply use Pike's <tt>import</tt> statement:
|
||||
|
||||
<blockquote><pre>
|
||||
|
|
@ -70,16 +98,21 @@ Pike v7.4 release 10 running Hilfe v3.5 (Incremental Pike Frontend)
|
|||
(1) Result: 24
|
||||
</pre></blockquote>
|
||||
|
||||
<h2>Basic C/C++ Mapping</h2>
|
||||
<a name="n6"></a><H2>5.2 Basic C/C++ Mapping</H2>
|
||||
|
||||
|
||||
<a name="n7"></a><H3>5.2.1 Modules</H3>
|
||||
|
||||
|
||||
<h3>Modules</h3>
|
||||
All of the code for a given SWIG module is wrapped into a single Pike
|
||||
module. Since the name of the shared library that implements your
|
||||
module ultimately determines the module's name (as far as Pike is
|
||||
concerned), SWIG's <tt>%module</tt> directive doesn't really have any
|
||||
significance.
|
||||
|
||||
<h3>Functions</h3>
|
||||
<a name="n8"></a><H3>5.2.2 Functions</H3>
|
||||
|
||||
|
||||
Global functions are wrapped as new Pike built-in functions. For
|
||||
example,
|
||||
|
||||
|
|
@ -98,7 +131,8 @@ exactly as you'd expect it to:
|
|||
(1) Result: 24
|
||||
</pre></blockquote>
|
||||
|
||||
<h3>Global variables</h3>
|
||||
<a name="n9"></a><H3>5.2.3 Global variables</H3>
|
||||
|
||||
|
||||
Global variables are currently wrapped as a pair of of functions, one to get
|
||||
the current value of the variable and another to set it. For example, the
|
||||
|
|
@ -122,8 +156,38 @@ will result in two functions, <tt>Foo_get()</tt> and <tt>Foo_set()</tt>:
|
|||
(3) Result: 3.141590
|
||||
</pre></blockquote>
|
||||
|
||||
<h3>Constants and enumerated types</h3>
|
||||
<a name="n10"></a><H3>5.2.4 Constants and enumerated types</H3>
|
||||
|
||||
|
||||
Enumerated types in C/C++ declarations are wrapped as Pike constants,
|
||||
not as Pike enums.
|
||||
|
||||
<a name="n11"></a><H3>5.2.5 Constructors and Destructors</H3>
|
||||
|
||||
|
||||
Constructors are wrapped as <tt>create()</tt> methods, and destructors are
|
||||
wrapped as <tt>destroy()</tt> methods, for Pike classes.
|
||||
|
||||
<a name="n12"></a><H3>5.2.6 Static Members</H3>
|
||||
|
||||
|
||||
Since Pike doesn't support static methods or data for Pike classes, static
|
||||
member functions in your C++ classes are wrapped as regular functions and
|
||||
static member variables are wrapped as pairs of functions (one to get the
|
||||
value of the static member variable, and another to set it). The names of
|
||||
these functions are prepended with the name of the class.
|
||||
For example, given this C++ class declaration:
|
||||
|
||||
<blockquote><pre>
|
||||
class Shape
|
||||
{
|
||||
public:
|
||||
static void print();
|
||||
static int nshapes;
|
||||
};
|
||||
</pre></blockquote>
|
||||
|
||||
SWIG will generate a <tt>Shape_print()</tt> method that invokes the static
|
||||
<tt>Shape::print()</tt> member function, as well as a pair of methods,
|
||||
<tt>Shape_nshapes_get()</tt> and <tt>Shape_nshapes_set()</tt>, to get and set
|
||||
the value of <tt>Shape::nshapes</tt>.
|
||||
Loading…
Add table
Add a link
Reference in a new issue