Fix some typos in docs and examples and make the code look nicer.

This commit is contained in:
sunoru 2016-12-31 23:06:56 +08:00
commit 8985c34809
45 changed files with 717 additions and 717 deletions

View file

@ -526,8 +526,8 @@ interested in generating an interface to C++.
<pre>
%module ffargs
%ffargs(strings_convert="nil",call_direct="t") foo;
%ffargs(strings_convert="nil",release_heap=":never",optimize_for_space="t") bar;
%ffargs(strings_convert="nil", call_direct="t") foo;
%ffargs(strings_convert="nil", release_heap=":never", optimize_for_space="t") bar;
int foo(float f1, float f2);
int foo(float f1, char c2);
@ -1357,7 +1357,7 @@ EXPORT float ACL___xxx__SWIG_0 (int larg1, int larg2) {
arg1 = larg1;
arg2 = larg2;
try {
result = (float)xxx(arg1,arg2);
result = (float)xxx(arg1, arg2);
lresult = result;
return lresult;
@ -1393,7 +1393,7 @@ EXPORT float ACL___xxx__SWIG_2 (A *larg1, int larg2) {
arg1 = larg1;
arg2 = larg2;
try {
result = (float)xxx(arg1,arg2);
result = (float)xxx(arg1, arg2);
lresult = result;
return lresult;
@ -1526,8 +1526,8 @@ overload&gt;
%rename(__predecr__) *::operator--();
%rename(__postdecr__) *::operator--(int);
%rename(__comma__) *::operator,();
%rename(__comma__) *::operator,() const;
%rename(__comma__) *::operator, ();
%rename(__comma__) *::operator, () const;
%rename(__member_ref__) *::operator-&gt;;
%rename(__member_func_ref__) *::operator-&gt;*;

View file

@ -354,7 +354,7 @@ Modify the <tt>nativeCall</tt> method in <tt>src/org/swig/simple/SwigSimple.java
int x = 42;
int y = 105;
int g = example.gcd(x,y);
int g = example.gcd(x, y);
outputText.append("The greatest common divisor of " + x + " and " + y + " is " + g + "\n");
// Manipulate the Foo global variable
@ -661,7 +661,7 @@ public class SwigClass extends Activity
// ----- Call some methods -----
outputText.append( "\nHere are some properties of the shapes:\n" );
Shape[] shapes = {c,s};
Shape[] shapes = {c, s};
for (int i=0; i&lt;shapes.length; i++)
{
outputText.append( " " + shapes[i].toString() + "\n" );

View file

@ -100,7 +100,7 @@ like this (shown for Python):
</p>
<div class="targetlang"><pre>
&gt;&gt;&gt; a = add(3,4)
&gt;&gt;&gt; a = add(3, 4)
&gt;&gt;&gt; print a
7
&gt;&gt;&gt;
@ -148,7 +148,7 @@ For example, consider this code:
%include "typemaps.i"
%apply int *OUTPUT { int *width, int *height };
// Returns a pair (width,height)
// Returns a pair (width, height)
void getwinsize(int winid, int *width, int *height);
</pre>
</div>
@ -158,7 +158,7 @@ In this case, the function returns multiple values, allowing it to be used like
</p>
<div class="targetlang"><pre>
&gt;&gt;&gt; w,h = genwinsize(wid)
&gt;&gt;&gt; w, h = genwinsize(wid)
&gt;&gt;&gt; print w
400
&gt;&gt;&gt; print h
@ -245,7 +245,7 @@ When the function is used in the scripting language interpreter, it will work li
</p>
<div class="targetlang"><pre>
result = add(3,4)
result = add(3, 4)
</pre></div>
<H3><a name="Arguments_nn5">10.1.3 Output parameters</a></H3>

View file

@ -203,7 +203,7 @@ public:
<p>And then call this constructor from your target language, for example, in Python, the following will call the constructor taking the <tt>std::vector</tt>:</p>
<div class="targetlang"><pre>
&gt;&gt;&gt; c = Container( [1,2,3,4] )
&gt;&gt;&gt; c = Container( [1, 2, 3, 4] )
</pre></div>
<p>
@ -392,7 +392,7 @@ auto SomeStruct::FuncName(int x, int y) -&gt; int {
<div class="targetlang"><pre>
&gt;&gt;&gt; a = SomeStruct()
&gt;&gt;&gt; a.FuncName(10,5)
&gt;&gt;&gt; a.FuncName(10, 5)
15
</pre></div>
@ -1057,7 +1057,7 @@ It does not involve <tt>std::function</tt>.
<div class="targetlang"><pre>
t = Test()
b = t(1,2) # invoke C++ function object
b = t(1, 2) # invoke C++ function object
</pre></div>
<H3><a name="CPlusPlus11_type_traits_for_metaprogramming">7.3.9 Type traits for metaprogramming</a></H3>

View file

@ -602,7 +602,7 @@ For the <tt>%array_functions</tt> example, the equivalent usage would be:
<pre>
SWIGTYPE_p_double a = example.new_doubleArray(10); // Create an array
for (int i=0; i&lt;10; i++)
example.doubleArray_setitem(a,i,2*i); // Set a value
example.doubleArray_setitem(a, i, 2*i); // Set a value
example.print_array(a); // Pass to C
example.delete_doubleArray(a); // Destroy array
</pre>
@ -1684,7 +1684,7 @@ void SwigDirector_Base::BaseBoolMethod(Base const &amp;b, bool flag) {
unsigned int jflag ;
if (!swig_callbackBaseBoolMethod) {
Base::BaseBoolMethod(b,flag);
Base::BaseBoolMethod(b, flag);
return;
} else {
jb = (Base *) &amp;b;
@ -2160,7 +2160,7 @@ The typemaps to achieve this are shown below.
%typemap(cstype) CDate &amp; "out System.DateTime"
%typemap(csin,
pre=" CDate temp$csinput = new CDate();",
post=" $csinput = new System.DateTime(temp$csinput.getYear(),"
post=" $csinput = new System.DateTime(temp$csinput.getYear(), "
" temp$csinput.getMonth(), temp$csinput.getDay(), 0, 0, 0);",
cshin="out $csinput"
) CDate &amp;
@ -2266,7 +2266,7 @@ will be possible with the following <tt>CDate *</tt> typemaps
%typemap(csin,
pre=" CDate temp$csinput = new CDate($csinput.Year, $csinput.Month, $csinput.Day);",
post=" $csinput = new System.DateTime(temp$csinput.getYear(),"
post=" $csinput = new System.DateTime(temp$csinput.getYear(), "
" temp$csinput.getMonth(), temp$csinput.getDay(), 0, 0, 0);",
cshin="ref $csinput"
) CDate *
@ -2305,7 +2305,7 @@ The <tt>subtractYears</tt> method is nearly identical to the above <tt>addYears<
<pre>
%typemap(csin,
pre=" using (CDate temp$csinput = new CDate($csinput.Year, $csinput.Month, $csinput.Day)) {",
post=" $csinput = new System.DateTime(temp$csinput.getYear(),"
post=" $csinput = new System.DateTime(temp$csinput.getYear(), "
" temp$csinput.getMonth(), temp$csinput.getDay(), 0, 0, 0);",
terminator=" } // terminate temp$csinput using block",
cshin="ref $csinput"
@ -2377,7 +2377,7 @@ The typemap type required is thus <tt>CDate *</tt>. Given that the previous sect
%typemap(csin,
pre=" CDate temp$csinput = new CDate($csinput.Year, $csinput.Month, $csinput.Day);",
post=" $csinput = new System.DateTime(temp$csinput.getYear(),"
post=" $csinput = new System.DateTime(temp$csinput.getYear(), "
" temp$csinput.getMonth(), temp$csinput.getDay(), 0, 0, 0);",
cshin="ref $csinput"
) CDate *

View file

@ -297,7 +297,7 @@
The author of TinyCLOS, Gregor Kiczales, describes TinyCLOS as:
"Tiny CLOS is a Scheme implementation of a `kernelized' CLOS, with a
metaobject protocol. The implementation is even simpler than
the simple CLOS found in `The Art of the Metaobject Protocol,'
the simple CLOS found in `The Art of the Metaobject Protocol, '
weighing in at around 850 lines of code, including (some)
comments and documentation."
</p>
@ -420,7 +420,7 @@ See the
Loading-extension-libraries in the eval unit inside the CHICKEN manual for more information.</p>
<p>Another alternative is to run SWIG normally and create a scheme file that contains <code>(declare (uses <i>modname</i>))</code>
and then compile that file into the shared library as well. For example, inside the <tt>mod_load.scm</tt> file,</p>
and then compile that file into the shared library as well. For example, inside the <tt>mod_load.scm</tt> file, </p>
<div class="targetlang">
<pre>

View file

@ -133,7 +133,7 @@ Thus, any contract that you specified for a base class will also be attached to
<pre>
class Spam : public Foo {
public:
int bar(int,int); // Gets contract defined for Foo::bar(int,int)
int bar(int, int); // Gets contract defined for Foo::bar(int, int)
};
</pre>
</div>
@ -156,12 +156,12 @@ require:
class Foo {
public:
int bar(int,int); // Gets Foo::bar contract.
int bar(int, int); // Gets Foo::bar contract.
};
class Spam : public Foo {
public:
int bar(int,int); // Gets Foo::bar and Spam::bar contract
int bar(int, int); // Gets Foo::bar and Spam::bar contract
};
</pre>
</div>

View file

@ -75,7 +75,7 @@ How the exception is handled depends on the target language, for example, Python
$action
}
catch (RangeError) {
PyErr_SetString(PyExc_IndexError,"index out-of-bounds");
PyErr_SetString(PyExc_IndexError, "index out-of-bounds");
SWIG_fail;
}
}
@ -116,7 +116,7 @@ static char error_message[256];
static int error_status = 0;
void throw_exception(char *msg) {
strncpy(error_message,msg,256);
strncpy(error_message, msg, 256);
error_status = 1;
}
@ -193,7 +193,7 @@ extern int exception_status;
#define try if ((exception_status = setjmp(exception_buffer)) == 0)
#define catch(val) else if (exception_status == val)
#define throw(val) longjmp(exception_buffer,val)
#define throw(val) longjmp(exception_buffer, val)
#define finally else
/* Exception codes */
@ -569,7 +569,7 @@ common scripting language exceptions in a portable manner. For example :</p>
} catch(OutOfMemory) {
SWIG_exception(SWIG_MemoryError, "Out of memory");
} catch(...) {
SWIG_exception(SWIG_RuntimeError,"Unknown exception");
SWIG_exception(SWIG_RuntimeError, "Unknown exception");
}
}
@ -645,7 +645,7 @@ you can attach it to class members and parameterized declarations as before. Fo
<div class="code">
<pre>
%newobject ::blah(); // Only applies to global blah
%newobject Object::blah(int,double); // Only blah(int,double) in Object
%newobject Object::blah(int, double); // Only blah(int, double) in Object
%newobject *::copy; // Copy method in all classes
...
</pre>
@ -779,7 +779,7 @@ using the <tt>%feature</tt> directive. For example:
}
}
%feature("new","1") *::copy;
%feature("new", "1") *::copy;
</pre>
</div>
@ -791,7 +791,7 @@ involving <tt>%feature</tt>:
<div class="code">
<pre>
#define %exception %feature("except")
#define %newobject %feature("new","1")
#define %newobject %feature("new", "1")
</pre>
</div>
@ -831,7 +831,7 @@ The following are all equivalent:
%feature("except") Object::method { $action };
%feature("except") Object::method %{ $action %};
%feature("except") Object::method " $action ";
%feature("except","$action") Object::method;
%feature("except", "$action") Object::method;
</pre>
</div>
@ -850,7 +850,7 @@ The following is the generic syntax for features:
<div class="code">
<pre>
%feature("name","value", attribute1="AttributeValue1") symbol;
%feature("name", "value", attribute1="AttributeValue1") symbol;
%feature("name", attribute1="AttributeValue1") symbol {value};
%feature("name", attribute1="AttributeValue1") symbol %{value%};
%feature("name", attribute1="AttributeValue1") symbol "value";
@ -914,13 +914,13 @@ int red; // mutable
%feature("immutable"); // global enable
int orange; // immutable
%feature("immutable","0"); // global disable
%feature("immutable", "0"); // global disable
int yellow; // mutable
%feature("immutable","1"); // another form of global enable
%feature("immutable", "1"); // another form of global enable
int green; // immutable
%feature("immutable",""); // clears the global feature
%feature("immutable", ""); // clears the global feature
int blue; // mutable
</pre>
</div>
@ -932,8 +932,8 @@ The above intersperses SWIG directives with C code. Of course you can target fea
<div class="code">
<pre>
%feature("immutable","1") orange;
%feature("immutable","1") green;
%feature("immutable", "1") orange;
%feature("immutable", "1") green;
int red; // mutable
int orange; // immutable
int yellow; // mutable
@ -949,10 +949,10 @@ The logic above can of course be inverted and rewritten as:
<div class="code">
<pre>
%feature("immutable","1");
%feature("immutable","0") red;
%feature("immutable","0") yellow;
%feature("immutable","0") blue;
%feature("immutable", "1");
%feature("immutable", "0") red;
%feature("immutable", "0") yellow;
%feature("immutable", "0") blue;
int red; // mutable
int orange; // immutable
int yellow; // mutable
@ -983,7 +983,7 @@ The concept of clearing features is discussed next.
<p>
A feature stays in effect until it is explicitly cleared. A feature is cleared by
supplying a <tt>%feature</tt> directive with no value. For example <tt>%feature("name","")</tt>.
supplying a <tt>%feature</tt> directive with no value. For example <tt>%feature("name", "")</tt>.
A cleared feature means that any feature exactly matching any previously defined feature is no longer used in the name matching rules.
So if a feature is cleared, it might mean that another name matching rule will apply.
To clarify, let's consider the <tt>except</tt> feature again (<tt>%exception</tt>):
@ -1013,7 +1013,7 @@ To clarify, let's consider the <tt>except</tt> feature again (<tt>%exception</tt
... initial set of class declarations with clone methods ...
// clear the previously defined feature
%feature("except","") *::clone();
%feature("except", "") *::clone();
... final set of class declarations with clone methods ...
</pre>
@ -1027,8 +1027,8 @@ However, these clone methods will still have an exception handler (without loggi
<p>
Note that clearing a feature is not always the same as disabling it.
Clearing the feature above with <tt>%feature("except","") *::clone()</tt> is not the same as specifying
<tt>%feature("except","0") *::clone()</tt>. The former will disable the feature for clone methods -
Clearing the feature above with <tt>%feature("except", "") *::clone()</tt> is not the same as specifying
<tt>%feature("except", "0") *::clone()</tt>. The former will disable the feature for clone methods -
the feature is still a better match than the global feature.
If on the other hand, no global exception handler had been defined at all,
then clearing the feature would be the same as disabling it as no other feature would have matched.
@ -1042,7 +1042,7 @@ For example the following attempt to clear the initial feature will not work:
<div class="code">
<pre>
%feature("except") clone() { logger.info("$action"); $action }
%feature("except","") *::clone();
%feature("except", "") *::clone();
</pre>
</div>
@ -1053,7 +1053,7 @@ but this will:
<div class="code">
<pre>
%feature("except") clone() { logger.info("$action"); $action }
%feature("except","") clone();
%feature("except", "") clone();
</pre>
</div>
@ -1066,8 +1066,8 @@ The three macros below show this for the "except" feature:
<div class="code">
<pre>
#define %exception %feature("except")
#define %noexception %feature("except","0")
#define %clearexception %feature("except","")
#define %noexception %feature("except", "0")
#define %clearexception %feature("except", "")
</pre>
</div>
@ -1158,15 +1158,15 @@ in the Python module. You might use <tt>%feature</tt> to rewrite proxy/shadow cl
<div class="code">
<pre>
%module example
%rename(bar_id) bar(int,double);
%rename(bar_id) bar(int, double);
// Rewrite bar() to allow some nice overloading
%feature("shadow") Foo::bar(int) %{
def bar(*args):
if len(args) == 3:
return apply(examplec.Foo_bar_id,args)
return apply(examplec.Foo_bar,args)
return apply(examplec.Foo_bar_id, args)
return apply(examplec.Foo_bar, args)
%}
class Foo {

View file

@ -422,7 +422,7 @@ struct A {
<p>As with any other language, the SWIG test-suite can be built for D using the <tt>*-d-test-suite</tt> targets of the top-level Makefile. By default, D1 is targeted, to build it with D2, use the optional <tt>D_VERSION</tt> variable, e.g. <tt>make check-d-test-suite D_VERSION=2</tt>.</p>
<p>Note: If you want to use GDC on Linux or another platform which requires you to link <tt>libdl</tt> for dynamically loading the shared library, you might have to add <tt>-ldl</tt> manually to the <tt>d_compile</tt> target in <tt>Examples/Makefile</tt>, because GDC does not currently honor the <tt>pragma(lib,...)</tt> statement.</p>
<p>Note: If you want to use GDC on Linux or another platform which requires you to link <tt>libdl</tt> for dynamically loading the shared library, you might have to add <tt>-ldl</tt> manually to the <tt>d_compile</tt> target in <tt>Examples/Makefile</tt>, because GDC does not currently honor the <tt>pragma(lib, ...)</tt> statement.</p>
<H2><a name="D_typemap_examples">22.9 D Typemap examples</a></H2>

View file

@ -243,7 +243,7 @@ of <tt>swig.swg</tt> looks like this:
/* Access control directives */
#define %immutable %feature("immutable","1")
#define %immutable %feature("immutable", "1")
#define %mutable %feature("immutable")
/* Directives for callback functions */
@ -306,7 +306,7 @@ datatype such as <tt>int</tt> or <tt>void</tt>. <tt><em>type</em></tt> may be
qualified with a qualifier such as <tt>const</tt> or <tt>volatile</tt>. <tt><em>declarator</em></tt>
is a name with additional type-construction modifiers attached to it (pointers, arrays, references,
functions, etc.). Examples of declarators include <tt>*x</tt>, <tt>**x</tt>, <tt>x[20]</tt>, and
<tt>(*x)(int,double)</tt>. The <tt><em>initializer</em></tt> may be a value assigned using <tt>=</tt> or
<tt>(*x)(int, double)</tt>. The <tt><em>initializer</em></tt> may be a value assigned using <tt>=</tt> or
body of code enclosed in braces <tt>{ ... }</tt>.
</p>
@ -372,7 +372,7 @@ For example, in an old C program, you might see things like this:
<div class="code">
<pre>
foo(a,b) {
foo(a, b) {
...
}
</pre>
@ -516,8 +516,8 @@ $ swig -c++ -python -debug-module 4 example.i
+++ cdecl ----------------------------------------
| sym:name - "move"
| name - "move"
| decl - "f(double,double)."
| parms - double ,double
| decl - "f(double, double)."
| parms - double, double
| type - "void"
| sym:symtab - 0x40194140
|
@ -1381,14 +1381,14 @@ List *l = (some list);
Iterator i;
for (i = First(l); i.item; i = Next(i)) {
Printf(stdout,"%s\n", i.item);
Printf(stdout, "%s\n", i.item);
}
Hash *h = (some hash);
Iterator j;
for (j = First(j); j.item; j= Next(j)) {
Printf(stdout,"%s : %s\n", j.key, j.item);
Printf(stdout, "%s : %s\n", j.key, j.item);
}
</pre>
</div>
@ -1414,7 +1414,7 @@ operators have the same meaning.
</div>
<p>
<b><tt>int Printv(String_or_FILE *f, String_or_char *arg1,..., NULL)</tt></b>
<b><tt>int Printv(String_or_FILE *f, String_or_char *arg1, ..., NULL)</tt></b>
</p>
<div class="indent">
@ -1469,7 +1469,7 @@ Same as the C <tt>ungetc()</tt> function.
<div class="indent">
Same as the C <tt>seek()</tt> function. <tt>offset</tt> is the number
of bytes. <tt>whence</tt> is one of <tt>SEEK_SET</tt>,<tt>SEEK_CUR</tt>,
of bytes. <tt>whence</tt> is one of <tt>SEEK_SET</tt>, <tt>SEEK_CUR</tt>,
or <tt>SEEK_END</tt>..
</div>
@ -1515,9 +1515,9 @@ common to see small code fragments of code generated using code like this:
<pre>
/* Print into a string */
String *s = NewString("");
Printf(s,"Hello\n");
Printf(s, "Hello\n");
for (i = 0; i &lt; 10; i++) {
Printf(s,"%d\n", i);
Printf(s, "%d\n", i);
}
...
/* Print string into a file */
@ -1674,9 +1674,9 @@ Since parse tree nodes are just hash tables, attributes are accessed using the <
<div class="code">
<pre>
int functionHandler(Node *n) {
String *name = Getattr(n,"name");
String *symname = Getattr(n,"sym:name");
SwigType *type = Getattr(n,"type");
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
...
}
</pre>
@ -1691,7 +1691,7 @@ For example:
<div class="code">
<pre>
...
Setattr(n,"python:docstring", doc); /* Store docstring */
Setattr(n, "python:docstring", doc); /* Store docstring */
...
</pre>
</div>
@ -1702,7 +1702,7 @@ A quick way to check the value of an attribute is to use the <tt>checkAttribute(
<div class="code">
<pre>
if (checkAttribute(n,"storage","virtual")) {
if (checkAttribute(n, "storage", "virtual")) {
/* n is virtual */
...
}
@ -1723,7 +1723,7 @@ the following functions are used:
<div class="indent">
Saves a copy of attributes <tt>name1</tt>, <tt>name2</tt>, etc. from node <tt>n</tt>.
Copies of the attributes are actually resaved in the node in a different namespace which is
set by the <tt>ns</tt> argument. For example, if you call <tt>Swig_save("foo",n,"type",NIL)</tt>,
set by the <tt>ns</tt> argument. For example, if you call <tt>Swig_save("foo", n, "type", NIL)</tt>,
then the "type" attribute will be copied and saved as "foo:type". The namespace name itself is stored in
the "view" attribute of the node. If necessary, this can be examined to find out where previous
values of attributes might have been saved.
@ -1750,11 +1750,11 @@ Calls can be nested if necessary. Here is an example that shows how the functio
<div class="code">
<pre>
int variableHandler(Node *n) {
Swig_save("variableHandler",n,"type","sym:name",NIL);
String *symname = Getattr(n,"sym:name");
SwigType *type = Getattr(n,"type");
Swig_save("variableHandler", n, "type", "sym:name", NIL);
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
...
Append(symname,"_global"); // Change symbol name
Append(symname, "_global"); // Change symbol name
SwigType_add_pointer(type); // Add pointer
...
generate wrappers
@ -1808,7 +1808,7 @@ C datatype SWIG encoding (strings)
int "int"
int * "p.int"
const int * "p.q(const).int"
int (*x)(int,double) "p.f(int,double).int"
int (*x)(int, double) "p.f(int, double).int"
int [20][30] "a(20).a(30).int"
int (F::*)(int) "m(F).f(int).int"
vector&lt;int&gt; * "p.vector&lt;(int)&gt;"
@ -1817,8 +1817,8 @@ vector&lt;int&gt; * "p.vector&lt;(int)&gt;"
<p>
Reading the SWIG encoding is often easier than figuring out the C code---just
read it from left to right. For a type of "p.f(int,double).int" is
a "pointer to a function(int,double) that returns int".
read it from left to right. For a type of "p.f(int, double).int" is
a "pointer to a function(int, double) that returns int".
</p>
<p>
@ -1854,7 +1854,7 @@ an extremely perverted example:
<div class="diagram">
<pre>
`p.a(10).p.f(int,p.f(int).int)` foo(int, int (*x)(int));
`p.a(10).p.f(int, p.f(int).int)` foo(int, int (*x)(int));
</pre>
</div>
@ -1864,7 +1864,7 @@ This corresponds to the immediately obvious C declaration:
<div class="diagram">
<pre>
(*(*foo(int,int (*)(int)))[10])(int,int (*)(int));
(*(*foo(int, int (*)(int)))[10])(int, int (*)(int));
</pre>
</div>
@ -1947,7 +1947,7 @@ Returns number of array dimensions of <tt>ty</tt>.
</div>
<p>
<b><tt>String* SwigType_array_getdim(SwigType *ty,int n)</tt></b>
<b><tt>String* SwigType_array_getdim(SwigType *ty, int n)</tt></b>
</p>
<div class="indent">
@ -2375,9 +2375,9 @@ code like this:
Parm *parms;
Parm *p;
for (p = parms; p; p = nextSibling(p)) {
SwigType *type = Getattr(p,"type");
String *name = Getattr(p,"name");
String *value = Getattr(p,"value");
SwigType *type = Getattr(p, "type");
String *name = Getattr(p, "name");
String *value = Getattr(p, "value");
...
}
</pre>
@ -2537,7 +2537,7 @@ also return a pointer to the base class (<tt>Language</tt>) so that only the int
Save the code for your language module in a file named "<tt>python.cxx</tt>" and
place this file in the <tt>Source/Modules</tt> directory of the SWIG distribution.
To ensure that your module is compiled into SWIG along with the other language modules,
modify the file <tt>Source/Modules/Makefile.am</tt> to include the additional source
modify the file <tt>Source/Makefile.am</tt> to include the additional source
files. In addition, modify the file <tt>Source/Modules/swigmain.cxx</tt>
with an additional command line option that activates the module. Read the source---it's straightforward.
</p>
@ -2593,7 +2593,7 @@ command line options, simply use code similar to this:
void Language::main(int argc, char *argv[]) {
for (int i = 1; i &lt; argc; i++) {
if (argv[i]) {
if(strcmp(argv[i],"-interface") == 0) {
if (strcmp(argv[i], "-interface") == 0) {
if (argv[i+1]) {
interface = NewString(argv[i+1]);
Swig_mark_arg(i);
@ -2602,7 +2602,7 @@ void Language::main(int argc, char *argv[]) {
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i],"-globals") == 0) {
} else if (strcmp(argv[i], "-globals") == 0) {
if (argv[i+1]) {
global_name = NewString(argv[i+1]);
Swig_mark_arg(i);
@ -2611,14 +2611,14 @@ void Language::main(int argc, char *argv[]) {
} else {
Swig_arg_error();
}
} else if ( (strcmp(argv[i],"-proxy") == 0)) {
} else if ((strcmp(argv[i], "-proxy") == 0)) {
proxy_flag = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-keyword") == 0) {
} else if (strcmp(argv[i], "-keyword") == 0) {
use_kw = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stderr);
} else if (strcmp(argv[i], "-help") == 0) {
fputs(usage, stderr);
}
...
}
@ -2722,10 +2722,10 @@ An outline of <tt>top()</tt> might be as follows:
int Python::top(Node *n) {
/* Get the module name */
String *module = Getattr(n,"name");
String *module = Getattr(n, "name");
/* Get the output file name */
String *outfile = Getattr(n,"outfile");
String *outfile = Getattr(n, "outfile");
/* Initialize I/O (see next section) */
...
@ -2858,15 +2858,15 @@ A simple modification to write some basic details to the wrapper looks like this
<pre>
int Python::functionWrapper(Node *n) {
/* Get some useful attributes of this function */
String *name = Getattr(n,"sym:name");
SwigType *type = Getattr(n,"type");
ParmList *parms = Getattr(n,"parms");
String *name = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
ParmList *parms = Getattr(n, "parms");
String *parmstr= ParmList_str_defaultargs(parms); // to string
String *func = SwigType_str(type, NewStringf("%s(%s)", name, parmstr));
String *action = Getattr(n,"wrap:action");
String *action = Getattr(n, "wrap:action");
Printf(f_wrappers,"functionWrapper : %s\n", func);
Printf(f_wrappers," action : %s\n", action);
Printf(f_wrappers, "functionWrapper : %s\n", func);
Printf(f_wrappers, " action : %s\n", action);
return SWIG_OK;
}
</pre>
@ -2881,13 +2881,13 @@ This will now produce some useful information within your wrapper file.
functionWrapper : void delete_Shape(Shape *self)
action : delete arg1;
functionWrapper : void Shape_x_set(Shape *self,double x)
functionWrapper : void Shape_x_set(Shape *self, double x)
action : if (arg1) (arg1)-&gt;x = arg2;
functionWrapper : double Shape_x_get(Shape *self)
action : result = (double) ((arg1)-&gt;x);
functionWrapper : void Shape_y_set(Shape *self,double y)
functionWrapper : void Shape_y_set(Shape *self, double y)
action : if (arg1) (arg1)-&gt;y = arg2;
...
</pre>
@ -2918,7 +2918,7 @@ In general most language wrappers look a little like this:
</p>
<div class="code">
<pre>
/* wrapper for TYPE3 some_function(TYPE1,TYPE2); */
/* wrapper for TYPE3 some_function(TYPE1, TYPE2); */
RETURN_TYPE _wrap_some_function(ARGS){
TYPE1 arg1;
TYPE2 arg2;
@ -2929,7 +2929,7 @@ RETURN_TYPE _wrap_some_function(ARGS){
if(ARG2 is not of TYPE2) goto fail;
arg2=(convert ARG2);
result=some_function(arg1,arg2);
result=some_function(arg1, arg2);
convert 'result' to whatever the language wants;
@ -2973,9 +2973,9 @@ There are a lot of issues to address.
<pre>
virtual int functionWrapper(Node *n) {
/* get useful attributes */
String *name = Getattr(n,"sym:name");
SwigType *type = Getattr(n,"type");
ParmList *parms = Getattr(n,"parms");
String *name = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
ParmList *parms = Getattr(n, "parms");
...
/* create the wrapper object */
@ -2988,7 +2988,7 @@ virtual int functionWrapper(Node *n) {
....
/* write the wrapper function definition */
Printv(wrapper-&gt;def,"RETURN_TYPE ", wname, "(ARGS) {",NIL);
Printv(wrapper-&gt;def, "RETURN_TYPE ", wname, "(ARGS) {", NIL);
/* if any additional local variable needed, add them now */
...
@ -3006,7 +3006,7 @@ virtual int functionWrapper(Node *n) {
....
/* Emit the function call */
emit_action(n,wrapper);
emit_action(n, wrapper);
/* return value if necessary */
....
@ -3030,7 +3030,7 @@ virtual int functionWrapper(Node *n) {
...
/* Dump the function out */
Wrapper_print(wrapper,f_wrappers);
Wrapper_print(wrapper, f_wrappers);
/* tidy up */
Delete(wname);

View file

@ -1337,7 +1337,7 @@ func Modf(x float64) (fracPart float64, intPart float64) {
<p>For classes, since swig generates an interface, you can add additional
methods by defining another interface that includes the swig-generated
interface. For example,</p>
interface. For example, </p>
<div class="code">
<pre>
%rename(Wrapped_MyClass) MyClass;
@ -1372,7 +1372,7 @@ few, then you might as well define your own struct that includes the
swig-wrapped object, instead of adding methods to the swig-generated object.</p>
<p>If you need to import other go packages, you can do this with
<code>%go_import</code>. For example,</p>
<code>%go_import</code>. For example, </p>
<div class="code">
<pre>
%go_import("fmt", _ "unusedPackage", rp "renamed/package")

View file

@ -727,7 +727,7 @@ In the previous example, the GOOPS definitions will be in a file named Test.scm.
<p>Because of the naming conflicts, you can't in general use both the <code>-primitive</code> and the GOOPS
guile-modules at the same time. To do this, you need to rename the exported symbols from one or both
guile-modules. For example,</p>
guile-modules. For example, </p>
<div class="targetlang"><pre>
(use-modules ((Test-primitive) #:renamer (symbol-prefix-proc 'primitive:)))
(use-modules ((Test) #:renamer (symbol-prefix-proc 'goops:)))

View file

@ -251,7 +251,7 @@ unix &gt; <b>ld -G example.o example_wrap.o -o example.so</b> # This is for Sola
unix &gt; <b>perl5.003
use example;
print example::fact(4), "\n";
print example::my_mod(23,7), "\n";
print example::my_mod(23, 7), "\n";
print $example::My_variable + 4.5, "\n";
&lt;ctrl-d&gt;</b>
24
@ -279,7 +279,7 @@ Type "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; <b>import example</b>
&gt;&gt;&gt; <b>example.fact(4)</b>
24
&gt;&gt;&gt; <b>example.my_mod(23,7)</b>
&gt;&gt;&gt; <b>example.my_mod(23, 7)</b>
2
&gt;&gt;&gt; <b>example.cvar.My_variable + 4.5</b>
7.5
@ -303,7 +303,7 @@ unix &gt; <b>ld -G example.o example_wrap.o -o example.so</b>
unix &gt; <b>perl5.003
use example;
print example::fact(4), "\n";
print example::my_mod(23,7), "\n";
print example::my_mod(23, 7), "\n";
print $example::My_variable + 4.5, "\n";
&lt;ctrl-d&gt;</b>
24

View file

@ -563,7 +563,7 @@ Don't worry if the wrapper file doesn't exist yet--Visual Studio will keep a ref
<li>Enter "SWIG" in the description field.
<li>Enter "<tt>swig -java -o $(ProjDir)\$(InputName)_wrap.c $(InputPath)</tt>" in the "Build command(s) field"
<li>Enter "<tt>$(ProjDir)\$(InputName)_wrap.c</tt>" in the "Output files(s) field".
<li>Next, select the settings for the entire project and go to C/C++ tab and select the Preprocessor category . Add the include directories to the JNI header files under "Additional include directories", eg "C:\jdk1.3\include,C:\jdk1.3\include\win32".
<li>Next, select the settings for the entire project and go to C/C++ tab and select the Preprocessor category . Add the include directories to the JNI header files under "Additional include directories", eg "C:\jdk1.3\include, C:\jdk1.3\include\win32".
<li>Next, select the settings for the entire project and go to Link tab and select the General category. Set the name of the output file to match the name of your Java module (ie. example.dll).
<li>Next, select the example.c and example_wrap.c files and go to the C/C++ tab and select the Precompiled Headers tab in the project settings. Disabling precompiled headers for these files will overcome any precompiled header errors while building.
<li>Finally, add the java compilation as a post build rule in the Post-build step tab in project settings, eg, "c:\jdk1.3\bin\javac *.java"
@ -1267,7 +1267,7 @@ When wrapped, you will be able to use the functions in a natural way from Java.
<div class="code">
<pre>
SWIGTYPE_p_FILE f = example.fopen("junk","w");
SWIGTYPE_p_FILE f = example.fopen("junk", "w");
example.fputs("Hello World\n", f);
example.fclose(f);
</pre>
@ -1341,7 +1341,7 @@ member variables. For example,
<div class="code"><pre>
struct Vector {
double x,y,z;
double x, y, z;
};
</pre></div>
@ -1878,7 +1878,7 @@ submodules or packages. For example, if you have a file like this,
namespace foo {
int fact(int n);
struct Vector {
double x,y,z;
double x, y, z;
};
};
</pre>
@ -1978,7 +1978,7 @@ struct pair {
~pair();
};
%template(pairii) pair&lt;int,int&gt;;
%template(pairii) pair&lt;int, int&gt;;
</pre>
</div>
@ -1988,7 +1988,7 @@ In Java:
<div class="code">
<pre>
pairii p = new pairii(3,4);
pairii p = new pairii(3, 4);
int first = p.getFirst();
int second = p.getSecond();
</pre>
@ -4285,11 +4285,11 @@ From Java, you could then write code like this:
<pre>
Image im = new Image();
SWIGTYPE_p_a_4__double a = example.new_mat44();
example.mat44_set(a,0,0,1.0);
example.mat44_set(a,1,1,1.0);
example.mat44_set(a,2,2,1.0);
example.mat44_set(a, 0, 0, 1.0);
example.mat44_set(a, 1, 1, 1.0);
example.mat44_set(a, 2, 2, 1.0);
...
example.set_transform(im,a);
example.set_transform(im, a);
example.free_mat44(a);
</pre>
</div>
@ -4317,13 +4317,13 @@ Here is a simple example:
%}
struct Vector {
double x,y,z;
double x, y, z;
};
%extend Vector {
char *toString() {
static char tmp[1024];
sprintf(tmp,"Vector(%g,%g,%g)", $self-&gt;x,$self-&gt;y,$self-&gt;z);
sprintf(tmp, "Vector(%g, %g, %g)", $self-&gt;x, $self-&gt;y, $self-&gt;z);
return tmp;
}
Vector(double x, double y, double z) {
@ -4343,7 +4343,7 @@ Now, in Java
<div class="code">
<pre>
Vector v = new Vector(2,3,4);
Vector v = new Vector(2, 3, 4);
System.out.println(v);
</pre>
</div>
@ -4354,7 +4354,7 @@ will display
<div class="code">
<pre>
Vector(2,3,4)
Vector(2, 3, 4)
</pre>
</div>
@ -4606,10 +4606,10 @@ In Java, this allows you to pass simple values. For example:
<div class="code">
<pre>
int result = example.sub(7,4);
int result = example.sub(7, 4);
System.out.println("7 - 4 = " + result);
int[] sum = {0};
example.add(3,4,sum);
example.add(3, 4, sum);
System.out.println("3 + 4 = " + sum[0]);
</pre>
</div>
@ -4754,7 +4754,7 @@ extern void add(int x, int y, int *result);
</div>
<p>
The <tt>%pointer_functions(type,name)</tt> macro generates five helper functions that can be used to create,
The <tt>%pointer_functions(type, name)</tt> macro generates five helper functions that can be used to create,
destroy, copy, assign, and dereference a pointer. In this case, the functions are as follows:
</p>
@ -4775,20 +4775,20 @@ In Java, you would use the functions like this:
<div class="code">
<pre>
SWIGTYPE_p_int intPtr = example.new_intp();
example.add(3,4,intPtr);
example.add(3, 4, intPtr);
int result = example.intp_value(intPtr);
System.out.println("3 + 4 = " + result);
</pre>
</div>
<p>
If you replace <tt>%pointer_functions(int,intp)</tt> by <tt>%pointer_class(int,intp)</tt>, the interface is more class-like.
If you replace <tt>%pointer_functions(int, intp)</tt> by <tt>%pointer_class(int, intp)</tt>, the interface is more class-like.
</p>
<div class="code">
<pre>
intp intPtr = new intp();
example.add(3,4,intPtr.cast());
example.add(3, 4, intPtr.cast());
int result = intPtr.value();
System.out.println("3 + 4 = " + result);
</pre>
@ -4907,7 +4907,7 @@ int[] array = new int[10000000]; // Array of 10-million integers
for (int i=0; i&lt;array.length; i++) { // Set some values
array[i] = i;
}
int sum = example.sumitems(array,10000);
int sum = example.sumitems(array, 10000);
System.out.println("Sum = " + sum);
</pre>
</div>
@ -4939,7 +4939,7 @@ For example:
</div>
<p>
The <tt>%array_functions(type,name)</tt> macro generates four helper functions that can be used to create and
The <tt>%array_functions(type, name)</tt> macro generates four helper functions that can be used to create and
destroy arrays and operate on elements. In this case, the functions are as follows:
</p>
@ -4960,15 +4960,15 @@ In Java, you would use the functions like this:
<pre>
SWIGTYPE_p_int array = example.new_intArray(10000000); // Array of 10-million integers
for (int i=0; i&lt;10000; i++) { // Set some values
example.intArray_setitem(array,i,i);
example.intArray_setitem(array, i, i);
}
int sum = example.sumitems(array,10000);
int sum = example.sumitems(array, 10000);
System.out.println("Sum = " + sum);
</pre>
</div>
<p>
If you replace <tt>%array_functions(int,intp)</tt> by <tt>%array_class(int,intp)</tt>, the interface is more class-like
If you replace <tt>%array_functions(int, intp)</tt> by <tt>%array_class(int, intp)</tt>, the interface is more class-like
and a couple more helper functions are available for casting between the array and the type wrapper class.
</p>
@ -4989,9 +4989,9 @@ For instance, you will be able to do this in Java:
<pre>
intArray array = new intArray(10000000); // Array of 10-million integers
for (int i=0; i&lt;10000; i++) { // Set some values
array.setitem(i,i);
array.setitem(i, i);
}
int sum = example.sumitems(array.cast(),10000);
int sum = example.sumitems(array.cast(), 10000);
System.out.println("Sum = " + sum);
</pre>
</div>
@ -5491,7 +5491,7 @@ parameter is omitted):
<div class="code">
<pre>
int c = example.count('e',"Hello World");
int c = example.count('e', "Hello World");
</pre>
</div>
@ -5814,7 +5814,7 @@ Note that when the 'pre' or 'post' attributes are specified and the associated t
<p>
The standard SWIG special variables are available for use within typemaps as described in the <a href="Typemaps.html#Typemaps">Typemaps documentation</a>, for example <tt>$1</tt>, <tt>$input</tt>,<tt>$result</tt> etc.
The standard SWIG special variables are available for use within typemaps as described in the <a href="Typemaps.html#Typemaps">Typemaps documentation</a>, for example <tt>$1</tt>, <tt>$input</tt>, <tt>$result</tt> etc.
</p>
<p>
@ -6337,7 +6337,7 @@ For example, integers are converted as follows:
<div class="code">
<pre>
%typemap(directorin,descriptor="I") int "$input = (jint) $1;"
%typemap(directorin, descriptor="I") int "$input = (jint) $1;"
</pre>
</div>
@ -7072,7 +7072,7 @@ public class runme {
}
public static void main(String argv[]) {
String animals[] = {"Cat","Dog","Cow","Goat"};
String animals[] = {"Cat", "Dog", "Cow", "Goat"};
example.print_args(animals);
String args[] = example.get_args();
for (int i=0; i&lt;args.length; i++)

View file

@ -415,7 +415,7 @@ open new windows, and many more things.
var example = require("example");
var x = 18;
var y = 24;
var z = example.gcd(x,y);
var z = example.gcd(x, y);
document.querySelector('#x').innerHTML = x;
document.querySelector('#y').innerHTML = y;
document.querySelector('#z').innerHTML = z;
@ -467,7 +467,7 @@ var example = require("./build/Release/example");
// calling the global method
var x = 42;
var y = 105;
var g = example.gcd(x,y);
var g = example.gcd(x, y);
// Accessing the global variable
var f = example.Foo;
@ -742,7 +742,7 @@ t_register.replace("$jsparent", state.clazz(NAME_MANGLED))
.trim().
print(f_init_static_wrappers);</pre>
</div>
<p>A code template is registered with the <em>JSEmitter</em> via <code>fragment(name, &quot;template&quot;)</code>, e.g.,</p>
<p>A code template is registered with the <em>JSEmitter</em> via <code>fragment(name, &quot;template&quot;)</code>, e.g., </p>
<div class="code">
<pre>
%fragment ("jsc_variable_declaration", "templates")
@ -921,7 +921,7 @@ state.clazz(NAME, Getattr(n, "sym:name"));</pre>
<p>Applications with an embedded JavascriptCore should be able to present detailed exception messages that occur in the Javascript engine. Below is an example derived from code provided by Brian Barnes on how these exception details can be extracted.</p>
<div class="code">
<pre>
void script_exception_to_string(JSContextRef js_context,JSValueRef exception_value_ref,char* return_error_string, int return_error_string_max_length)
void script_exception_to_string(JSContextRef js_context, JSValueRef exception_value_ref, char* return_error_string, int return_error_string_max_length)
{
JSObjectRef exception_object;
JSValueRef value_ref;
@ -933,7 +933,7 @@ void script_exception_to_string(JSContextRef js_context,JSValueRef exception_val
exception_object = JSValueToObject(js_context, exception_value_ref, NULL);
/* source url */
strcpy(return_error_string,&quot;[&quot;);
strcpy(return_error_string, &quot;[&quot;);
jsstring_property_name = JSStringCreateWithUTF8CString(&quot;sourceURL&quot;);
value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &amp;temporary_exception);
JSStringRelease(jsstring_property_name);

View file

@ -115,7 +115,7 @@ this module is in generating pointers to primitive datatypes such as
</p>
<p>
<b><tt>%pointer_functions(type,name)</tt></b>
<b><tt>%pointer_functions(type, name)</tt></b>
</p>
<div class="indent">
@ -195,7 +195,7 @@ Now, in Python:
<pre>
&gt;&gt;&gt; import example
&gt;&gt;&gt; c = example.new_intp() # Create an "int" for storing result
&gt;&gt;&gt; example.add(3,4,c) # Call function
&gt;&gt;&gt; example.add(3, 4, c) # Call function
&gt;&gt;&gt; example.intp_value(c) # Dereference
7
&gt;&gt;&gt; example.delete_intp(c) # Delete
@ -205,7 +205,7 @@ Now, in Python:
</div>
<p>
<b><tt>%pointer_class(type,name)</tt></b>
<b><tt>%pointer_class(type, name)</tt></b>
</p>
<div class="indent">
@ -275,7 +275,7 @@ Now, in Python (using proxy classes)
<pre>
&gt;&gt;&gt; import example
&gt;&gt;&gt; c = example.intp() # Create an "int" for storing result
&gt;&gt;&gt; example.add(3,4,c) # Call function
&gt;&gt;&gt; example.add(3, 4, c) # Call function
&gt;&gt;&gt; c.value() # Dereference
7
</pre>
@ -331,7 +331,7 @@ raw C array data.
</p>
<p>
<b><tt>%array_functions(type,name)</tt></b>
<b><tt>%array_functions(type, name)</tt></b>
</p>
<div class="indent">
@ -414,8 +414,8 @@ Now, in a scripting language, you might write this:
<div class="code">
<pre>
a = new_doubleArray(10) # Create an array
for i in range(0,10):
doubleArray_setitem(a,i,2*i) # Set a value
for i in range(0, 10):
doubleArray_setitem(a, i, 2*i) # Set a value
print_array(a) # Pass to C
delete_doubleArray(a) # Destroy array
</pre>
@ -424,7 +424,7 @@ delete_doubleArray(a) # Destroy array
</div>
<p>
<b><tt>%array_class(type,name)</tt></b>
<b><tt>%array_class(type, name)</tt></b>
</p>
<div class="indent">
@ -479,7 +479,7 @@ Allows you to do this:
<pre>
import example
c = example.doubleArray(10) # Create double[10]
for i in range(0,10):
for i in range(0, 10):
c[i] = 2*i # Assign values
example.print_array(c) # Pass to C
</pre>
@ -507,7 +507,7 @@ This module defines macros for wrapping the low-level C memory allocation functi
</p>
<p>
<b><tt>%malloc(type [,name=type])</tt></b>
<b><tt>%malloc(type [, name=type])</tt></b>
</p>
<div class="indent">
@ -530,7 +530,7 @@ is not a valid identifier (e.g., "<tt>int *</tt>", "<tt>double **</tt>", etc.).
</div>
<p>
<b><tt>%calloc(type [,name=type])</tt></b>
<b><tt>%calloc(type [, name=type])</tt></b>
</p>
<div class="indent">
@ -551,7 +551,7 @@ If <tt>type</tt> is <tt>void</tt>, then the size parameter <tt>sz</tt> is requir
</div>
<p>
<b><tt>%realloc(type [,name=type])</tt></b>
<b><tt>%realloc(type [, name=type])</tt></b>
</p>
<div class="indent">
@ -574,7 +574,7 @@ it holds 100 integers.
</div>
<p>
<b><tt>%free(type [,name=type])</tt></b>
<b><tt>%free(type [, name=type])</tt></b>
</p>
<div class="indent">
@ -590,7 +590,7 @@ void free_<em>name</em>(<em>type</em> *ptr);
</div>
<p>
<b><tt>%sizeof(type [,name=type])</tt></b>
<b><tt>%sizeof(type [, name=type])</tt></b>
</p>
<div class="indent">
@ -606,7 +606,7 @@ Creates the constant:
</div>
<p>
<b><tt>%allocators(type [,name=type])</tt></b>
<b><tt>%allocators(type [, name=type])</tt></b>
</p>
<div class="indent"><p>
@ -716,14 +716,14 @@ Python example:
<div class="targetlang">
<pre>
&gt;&gt;&gt; a = intArray(10)
&gt;&gt;&gt; for i in range(0,10):
&gt;&gt;&gt; for i in range(0, 10):
... a[i] = i
&gt;&gt;&gt; b = cdata(a,40)
&gt;&gt;&gt; b = cdata(a, 40)
&gt;&gt;&gt; b
'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04
\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\t'
&gt;&gt;&gt; c = intArray(10)
&gt;&gt;&gt; memmove(c,b)
&gt;&gt;&gt; memmove(c, b)
&gt;&gt;&gt; print c[4]
4
&gt;&gt;&gt;
@ -735,7 +735,7 @@ Since the size of data is not always known, the following macro is also defined:
</p>
<p>
<b><tt>%cdata(type [,name=type])</tt></b>
<b><tt>%cdata(type [, name=type])</tt></b>
</p>
<div class="indent">
@ -855,7 +855,7 @@ Now, in the target language, you can use binary string data like this:
<div class="code">
<pre>
&gt;&gt;&gt; s = "H\x00\x15eg\x09\x20"
&gt;&gt;&gt; parity(s,0)
&gt;&gt;&gt; parity(s, 0)
</pre>
</div>
@ -920,7 +920,7 @@ implementation:
<pre>
void get_path(char *s) {
// Potential buffer overflow---uh, oh.
sprintf(s,"%s/%s", base_directory, sub_directory);
sprintf(s, "%s/%s", base_directory, sub_directory);
}
...
// Somewhere else in the C program
@ -1554,7 +1554,7 @@ To illustrate the use of this library, consider the following functions:
#include &lt;numeric&gt;
double average(std::vector&lt;int&gt; v) {
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
return std::accumulate(v.begin(), v.end(), 0.0)/v.size();
}
std::vector&lt;double&gt; half(const std::vector&lt;double&gt;&amp; v) {
@ -1565,8 +1565,8 @@ std::vector&lt;double&gt; half(const std::vector&lt;double&gt;&amp; v) {
}
void halve_in_place(std::vector&lt;double&gt;&amp; v) {
std::transform(v.begin(),v.end(),v.begin(),
std::bind2nd(std::divides&lt;double&gt;(),2.0));
std::transform(v.begin(), v.end(), v.begin(),
std::bind2nd(std::divides&lt;double&gt;(), 2.0));
}
</pre>
</div>
@ -1602,20 +1602,20 @@ Now, to illustrate the behavior in the scripting interpreter, consider this Pyth
<pre>
&gt;&gt;&gt; from example import *
&gt;&gt;&gt; iv = IntVector(4) # Create an vector&lt;int&gt;
&gt;&gt;&gt; for i in range(0,4):
&gt;&gt;&gt; for i in range(0, 4):
... iv[i] = i
&gt;&gt;&gt; average(iv) # Call method
1.5
&gt;&gt;&gt; average([0,1,2,3]) # Call with list
&gt;&gt;&gt; average([0, 1, 2, 3]) # Call with list
1.5
&gt;&gt;&gt; half([1,2,3]) # Half a list
(0.5,1.0,1.5)
&gt;&gt;&gt; halve_in_place([1,2,3]) # Oops
&gt;&gt;&gt; half([1, 2, 3]) # Half a list
(0.5, 1.0, 1.5)
&gt;&gt;&gt; halve_in_place([1, 2, 3]) # Oops
Traceback (most recent call last):
File "&lt;stdin&gt;", line 1, in ?
TypeError: Type error. Expected _p_std__vectorTdouble_t
&gt;&gt;&gt; dv = DoubleVector(4)
&gt;&gt;&gt; for i in range(0,4):
&gt;&gt;&gt; for i in range(0, 4):
... dv[i] = i
&gt;&gt;&gt; halve_in_place(dv) # Ok
&gt;&gt;&gt; for i in dv:
@ -1629,7 +1629,7 @@ TypeError: Type error. Expected _p_std__vectorTdouble_t
Traceback (most recent call last):
File "&lt;stdin&gt;", line 1, in ?
File "example.py", line 81, in __setitem__
def __setitem__(*args): return apply(examplec.DoubleVector___setitem__,args)
def __setitem__(*args): return apply(examplec.DoubleVector___setitem__, args)
IndexError: vector index out of range
&gt;&gt;&gt;
</pre>
@ -2014,7 +2014,7 @@ For example:
try {
$action
} catch (std::out_of_range&amp; e) {
SWIG_exception(SWIG_IndexError,const_cast&lt;char*&gt;(e.what()));
SWIG_exception(SWIG_IndexError, const_cast&lt;char*&gt;(e.what()));
}
}
</pre>

View file

@ -148,7 +148,7 @@ struct foo {
int pointer_func(void (*ClosureFun)( void* _fun, void* _data, void* _evt ), int p);
int func123(div_t * p,int **q[100],int r[][1000][10]);
int func123(div_t * p, int **q[100], int r[][1000][10]);
void lispsort_double (int n, double * array);
@ -170,11 +170,11 @@ The generated SWIG Code will be:
(cl:defmacro defanonenum (&amp;body enums)
"Converts anonymous enums to defconstants."
`(cl:progn ,@(cl:loop for value in enums
`(cl:progn , @(cl:loop for value in enums
for index = 0 then (cl:1+ index)
when (cl:listp value) do (cl:setf index (cl:second value)
value (cl:first value))
collect `(cl:defconstant ,value ,index))))
collect `(cl:defconstant , value , index))))
(cl:eval-when (:compile-toplevel :load-toplevel)
(cl:unless (cl:fboundp 'swig-lispify)
@ -280,7 +280,7 @@ Let's edit the interface file such that the C type "div_t*" is changed
%typemap(cin) div_t* ":my-pointer";
%feature("intern_function","1");
%feature("intern_function", "1");
%feature("export");
%feature("inline") lispsort_double;
@ -305,7 +305,7 @@ The <i>typemap(cin)</i> ensures that for all arguments which are input
The feature <i>intern_function</i> ensures that all C names are
interned using the <b>swig-lispify</b> function. The "1" given
to the feature is optional. The use of feature like
<i>%feature("intern_function","1");</i> globally enables
<i>%feature("intern_function", "1");</i> globally enables
interning for everything. If you want to target a single
function, or declaration then use the targeted version of
feature, <i>%feature("intern_function", "my-lispify")
@ -722,7 +722,7 @@ The ffi wrappers for functions and variables are generated as shown
extern "C" {
int pointer_func(void (*ClosureFun)( void* _fun, void* _data, void* _evt ), int y);
int func123(div_t * x,int **z[100],int y[][1000][10]);
int func123(div_t * x, int **z[100], int y[][1000][10]);
void lispsort_double (int n, double * array);

View file

@ -193,27 +193,27 @@ Normally Lua is embedded into another program and will be statically linked. An
extern int luaopen_example(lua_State* L); // declare the wrapped module
int main(int argc,char* argv[])
int main(int argc, char* argv[])
{
lua_State *L;
if (argc&lt;2)
{
printf("%s: &lt;filename.lua&gt;\n",argv[0]);
printf("%s: &lt;filename.lua&gt;\n", argv[0]);
return 0;
}
L=lua_open();
luaopen_base(L); // load basic libs (eg. print)
luaopen_example(L); // load the wrapped module
if (luaL_loadfile(L,argv[1])==0) // load and run the file
lua_pcall(L,0,0,0);
if (luaL_loadfile(L, argv[1])==0) // load and run the file
lua_pcall(L, 0, 0, 0);
else
printf("unable to load %s\n",argv[1]);
printf("unable to load %s\n", argv[1]);
lua_close(L);
return 0;
}
</pre></div>
<p>
A much improved set of code can be found in the Lua distribution <tt>src/lua/lua.c</tt>. Include your module, just add the external declaration &amp; add a <tt>#define LUA_EXTRALIBS {"example",luaopen_example}</tt>, at the relevant place.
A much improved set of code can be found in the Lua distribution <tt>src/lua/lua.c</tt>. Include your module, just add the external declaration &amp; add a <tt>#define LUA_EXTRALIBS {"example", luaopen_example}</tt>, at the relevant place.
</p>
<p>
The exact commands for compiling and linking vary from platform to platform. Here is a possible set of commands of doing this:
@ -272,8 +272,8 @@ require("example")
For those using Lua 5.0.x, you will also need an interpreter with the loadlib function (such as the default interpreter compiled with Lua). In order to dynamically load a module you must call the loadlib function with two parameters: the filename of the shared library, and the function exported by SWIG. Calling loadlib should return the function, which you then call to initialise the module
</p>
<div class="targetlang"><pre>
my_init=loadlib("example.so","luaopen_example") -- for Unix/Linux
--my_init=loadlib("example.dll","luaopen_example") -- for Windows
my_init=loadlib("example.so", "luaopen_example") -- for Unix/Linux
--my_init=loadlib("example.dll", "luaopen_example") -- for Windows
assert(my_init) -- make sure it's not nil
my_init() -- call the init fn of the lib
</pre></div>
@ -281,7 +281,7 @@ my_init() -- call the init fn of the lib
Or can be done in a single line of Lua code
</p>
<div class="targetlang"><pre>
assert(loadlib("example.so","luaopen_example"))()
assert(loadlib("example.so", "luaopen_example"))()
</pre></div>
@ -289,9 +289,9 @@ assert(loadlib("example.so","luaopen_example"))()
If the code didn't work, don't panic. The best thing to do is to copy the module and your interpreter into a single directory and then execute the interpreter and try to manually load the module (take care, all this code is case sensitive).
</p>
<div class="targetlang"><pre>
a,b,c=package.loadlib("example.so","luaopen_example") -- for Unix/Linux
--a,b,c=package.loadlib("example.dll","luaopen_example") -- for Windows
print(a,b,c)
a, b, c=package.loadlib("example.so", "luaopen_example") -- for Unix/Linux
--a, b, c=package.loadlib("example.dll", "luaopen_example") -- for Windows
print(a, b, c)
</pre></div>
<p>
Note: for Lua 5.0:<br>
@ -326,7 +326,7 @@ Assuming all goes well, you will be able to this:
</p>
<div class="targetlang"><pre>
$ ./my_lua
&gt; print(example.gcd(4,6))
&gt; print(example.gcd(4, 6))
2
&gt; print(example.Foo)
3
@ -373,7 +373,7 @@ This can easily overwrite existing functions, so this must be used with care.
This option is considered deprecated and will be removed in the near future.
</p>
<div class="targetlang"><pre>
&gt; for k,v in pairs(example) do _G[k]=v end
&gt; for k, v in pairs(example) do _G[k]=v end
&gt; print(fact(4))
24
&gt;
@ -411,7 +411,7 @@ SWIG will effectively generate two functions <tt>example.Foo_set()</tt> and <tt>
&gt; print(c)
3
&gt; c=5 -- this will not effect the original example.Foo
&gt; print(example.Foo,c)
&gt; print(example.Foo, c)
4 5
</pre></div>
<p>
@ -486,7 +486,7 @@ Because Lua doesn't really have the concept of constants, C/C++ constants are no
<div class="code"><pre>%module example
%constant int ICONST=42;
#define SCONST "Hello World"
enum Days{SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY};
enum Days{SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY};
</pre></div>
<p>
This is 'effectively' converted into the following Lua code:
@ -584,8 +584,8 @@ int fclose(FILE *);
When wrapped, you will be able to use the functions in a natural way from Lua. For example:
</p>
<div class="targetlang"><pre>
&gt; f=example.fopen("junk","w")
&gt; example.fputs("Hello World",f)
&gt; f=example.fopen("junk", "w")
&gt; example.fputs("Hello World", f)
&gt; example.fclose(f)
</pre></div>
<p>
@ -601,7 +601,7 @@ FILE * -- it's a FILE*
Lua enforces the integrity of its userdata, so it is virtually impossible to corrupt the data. But as the user of the pointer, you are responsible for freeing it, or closing any resources associated with it (just as you would in a C program). This does not apply so strictly to classes &amp; structs (see below). One final note: if a function returns a NULL pointer, this is not encoded as a userdata, but as a Lua nil.
</p>
<div class="targetlang"><pre>
&gt; f=example.fopen("not there","r") -- this will return a NULL in C
&gt; f=example.fopen("not there", "r") -- this will return a NULL in C
&gt; print(f)
nil
</pre></div>
@ -613,7 +613,7 @@ nil
If you wrap a C structure, it is also mapped to a Lua userdata. By adding a metatable to the userdata, this provides a very natural interface. For example,
</p>
<div class="code"><pre>struct Point{
int x,y;
int x, y;
};
</pre></div>
<p>
@ -623,7 +623,7 @@ is used as follows:
&gt; p=example.new_Point()
&gt; p.x=3
&gt; p.y=5
&gt; print(p.x,p.y)
&gt; print(p.x, p.y)
3 5
&gt;
</pre></div>
@ -953,8 +953,8 @@ public:
When wrapped, it works like you expect:
</p>
<div class="targetlang"><pre>
&gt; c = Complex(3,4)
&gt; d = Complex(7,8)
&gt; c = Complex(3, 4)
&gt; d = Complex(7, 8)
&gt; e = c + d
&gt; e:re()
10.0
@ -1000,18 +1000,18 @@ The current list of operators which can be overloaded (and the alternative funct
<li><tt>__le__</tt> operator<tt>&lt;=</tt>
</ul>
<p>
Note: in Lua, only the equals, less than, and less than equals operators are defined. The other operators (!=,&gt;,&gt;=) are achieved by using a logical not applied to the results of other operators.
Note: in Lua, only the equals, less than, and less than equals operators are defined. The other operators (!=, &gt;, &gt;=) are achieved by using a logical not applied to the results of other operators.
</p>
<p>
The following operators cannot be overloaded (mainly because they are not supported in Lua)<ul>
<li>++ and --<li>+=,-=,*= etc<li>% operator (you have to use math.mod)<li>assignment operator<li>all bitwise/logical operations</ul>
<li>++ and --<li>+=, -=, *= etc<li>% operator (you have to use math.mod)<li>assignment operator<li>all bitwise/logical operations</ul>
<p>
SWIG also accepts the <tt>__str__()</tt> member function which converts an object to a string. This function should return a const char*, preferably to static memory. This will be used for the <tt>print()</tt> and <tt>tostring()</tt> functions in Lua. Assuming the complex class has a function
</p>
<div class="code"><pre>const char* __str__()
{
static char buffer[255];
sprintf(buffer,"Complex(%g,%g)",this-&gt;re(),this-&gt;im());
sprintf(buffer, "Complex(%g, %g)", this-&gt;re(), this-&gt;im());
return buffer;
}
</pre></div>
@ -1019,14 +1019,14 @@ SWIG also accepts the <tt>__str__()</tt> member function which converts an objec
Then this will support the following code in Lua
</p>
<div class="targetlang"><pre>
&gt; c = Complex(3,4)
&gt; d = Complex(7,8)
&gt; c = Complex(3, 4)
&gt; d = Complex(7, 8)
&gt; e = c + d
&gt; print(e)
Complex(10,12)
Complex(10, 12)
&gt; s=tostring(e) -- s is the number in string form
&gt; print(s)
Complex(10,12)
Complex(10, 12)
</pre></div>
<p>
It is also possible to overload the operator<tt>[]</tt>, but currently this cannot be automatically performed. To overload the operator<tt>[]</tt> you need to provide two functions, <tt>__getitem__()</tt> and <tt>__setitem__()</tt>
@ -1035,7 +1035,7 @@ It is also possible to overload the operator<tt>[]</tt>, but currently this cann
{
//....
double __getitem__(int i)const; // i is the index, returns the data
void __setitem__(int i,double d); // i is the index, d is the data
void __setitem__(int i, double d); // i is the index, d is the data
};
</pre></div>
<p>
@ -1092,7 +1092,7 @@ Now we extend it with some new code
<div class="code"><pre>%extend Complex {
const char *__str__() {
static char tmp[1024];
sprintf(tmp,"Complex(%g,%g)", $self-&gt;re(),$self-&gt;im());
sprintf(tmp, "Complex(%g, %g)", $self-&gt;re(), $self-&gt;im());
return tmp;
}
bool operator==(const Complex&amp; c) {
@ -1104,14 +1104,14 @@ Now we extend it with some new code
Now, in Lua
</p>
<div class="targetlang"><pre>
&gt; c = Complex(3,4)
&gt; d = Complex(7,8)
&gt; c = Complex(3, 4)
&gt; d = Complex(7, 8)
&gt; e = c + d
&gt; print(e) -- print uses __str__ to get the string form to print
Complex(10,12)
&gt; print(e==Complex(10,12)) -- testing the == operator
Complex(10, 12)
&gt; print(e==Complex(10, 12)) -- testing the == operator
true
&gt; print(e!=Complex(12,12)) -- the != uses the == operator
&gt; print(e!=Complex(12, 12)) -- the != uses the == operator
true
</pre></div>
<p>
@ -1121,7 +1121,7 @@ Extend works with both C and C++ code, on classes and structs. It does not modif
<H3><a name="Lua_nn20">28.3.13 Using %newobject to release memory</a></H3>
<p> If you have a function that allocates memory like this,</p>
<p> If you have a function that allocates memory like this, </p>
<div class="code">
<pre>char *foo() {
char *result = (char *) malloc(...);
@ -1164,14 +1164,14 @@ struct pair {
~pair();
};
%template(pairii) pair&lt;int,int&gt;;
%template(pairii) pair&lt;int, int&gt;;
</pre></div>
<p>
In Lua:
</p>
<div class="targetlang"><pre>
&gt; p = example.pairii(3,4)
&gt; print(p.first,p.second)
&gt; p = example.pairii(3, 4)
&gt; print(p.first, p.second)
3 4
</pre></div>
<p>
@ -1265,11 +1265,11 @@ Using xpcall will allow you to obtain additional debug information (such as a st
<div class="targetlang"><pre>
&gt; function a() b() end -- function a() calls function b()
&gt; function b() message() end -- function b() calls C++ function message(), which throws
&gt; ok,res=pcall(a) -- call the function
&gt; print(ok,res)
&gt; ok, res=pcall(a) -- call the function
&gt; print(ok, res)
false I died.
&gt; ok,res=xpcall(a,debug.traceback) -- call the function
&gt; print(ok,res)
&gt; ok, res=xpcall(a, debug.traceback) -- call the function
&gt; print(ok, res)
false I died.
stack traceback:
[C]: in function 'message'
@ -1322,7 +1322,7 @@ If you have your own class which you want output as a string you will need to ad
<div class="code"><pre>
%typemap(throws) my_except
%{
lua_pushstring(L,$1.what()); // assuming my_except::what() returns a const char* message
lua_pushstring(L, $1.what()); // assuming my_except::what() returns a const char* message
SWIG_fail; // trigger the error handler
%}
</pre></div>
@ -1337,26 +1337,26 @@ class Exc {
public:
Exc(int c, const char *m) {
code = c;
strncpy(msg,m,256);
strncpy(msg, m, 256);
}
int code;
char msg[256];
};
void throw_exc() throw(Exc) {
throw(Exc(42,"Hosed"));
throw(Exc(42, "Hosed"));
}
</pre></div>
<p>
Then the following code can be used (note: we use pcall to catch the error so we can process the exception).
</p>
<div class="targetlang"><pre>
&gt; ok,res=pcall(throw_exc)
&gt; ok, res=pcall(throw_exc)
&gt; print(ok)
false
&gt; print(res)
userdata: 0003D880
&gt; print(res.code,res.msg)
&gt; print(res.code, res.msg)
42 Hosed
&gt;
</pre></div>
@ -1537,8 +1537,8 @@ function
<div class="code"><pre>%module example
%typemap(in) int {
$1 = (int) lua_tonumber(L,$input);
printf("Received an integer : %d\n",$1);
$1 = (int) lua_tonumber(L, $input);
printf("Received an integer : %d\n", $1);
}
%inline %{
extern int fact(int n);
@ -1596,13 +1596,13 @@ void swap(int *sx, int *sy);
<p>When wrapped, it gives the following results:</p>
<div class="targetlang"><pre>&gt; require "example"
&gt; print(example.add(1,2))
&gt; print(example.add(1, 2))
3
&gt; print(demo.sub(1,2))
&gt; print(demo.sub(1, 2))
-1
&gt; a,b=1,2
&gt; c,d=demo.swap(a,b)
&gt; print(a,b,c,d)
&gt; a, b=1, 2
&gt; c, d=demo.swap(a, b)
&gt; print(a, b, c, d)
1 2 2 1
</pre></div>
@ -1633,13 +1633,13 @@ More details can be found in the <a href="Library.html#Library_carrays">carrays.
<div class="code"><pre>// using the C-array
%include &lt;carrays.i&gt;
// this declares a batch of function for manipulating C integer arrays
%array_functions(int,int)
%array_functions(int, int)
extern void sort_int(int* arr, int len); // the function to wrap
// using typemaps
%include &lt;typemaps.i&gt;
%apply (double *INOUT,int) {(double* arr,int len)};
%apply (double *INOUT, int) {(double* arr, int len)};
extern void sort_double(double* arr, int len); // the function to wrap
</pre></div>
@ -1651,16 +1651,16 @@ ARRAY_SIZE=10
-- passing a C array to the sort_int()
arr=example.new_int(ARRAY_SIZE) -- create the array
for i=0,ARRAY_SIZE-1 do -- index 0..9 (just like C)
example.int_setitem(arr,i,math.random(1000))
for i=0, ARRAY_SIZE-1 do -- index 0..9 (just like C)
example.int_setitem(arr, i, math.random(1000))
end
example.sort_int(arr,ARRAY_SIZE) -- call the function
example.sort_int(arr, ARRAY_SIZE) -- call the function
example.delete_int(arr) -- must delete the allocated memory
-- use a typemap to call with a Lua-table
-- one item of note: the typemap creates a copy, rather than edit-in-place
t={} -- a Lua table
for i=1,ARRAY_SIZE do -- index 1..10 (Lua style)
for i=1, ARRAY_SIZE do -- index 1..10 (Lua style)
t[i]=math.random(1000)/10
end
t=example.sort_double(t) -- replace t with the result
@ -1704,7 +1704,7 @@ int Create_Math(iMath** pptr); // its creator (assume it mallocs)
<p>The usage is as follows:</p>
<div class="targetlang"><pre>ok,ptr=Create_Math() -- ptr is an iMath* which is returned with the int (ok)
<div class="targetlang"><pre>ok, ptr=Create_Math() -- ptr is an iMath* which is returned with the int (ok)
ptr=nil -- the iMath* will be GC'ed as normal
</pre></div>
@ -1735,7 +1735,7 @@ ptr=nil -- the iMath* will be GC'ed as normal
<p>This section explains the SWIG specific Lua-C API. It does not cover the main Lua-C api, as this is well documented and not worth covering.</p>
<p><tt>int SWIG_ConvertPtr(lua_State* L,int index,void** ptr,swig_type_info *type,int flags);</tt></p>
<p><tt>int SWIG_ConvertPtr(lua_State* L, int index, void** ptr, swig_type_info *type, int flags);</tt></p>
<div class="indent">
This is the standard function used for converting a Lua userdata to a void*. It takes the value at the given index in the Lua state and converts it to a userdata. It will then provide the necessary type checks, confirming that the pointer is compatible with the type given in 'type'. Then finally setting '*ptr' to the pointer.
@ -1743,14 +1743,14 @@ If flags is set to SWIG_POINTER_DISOWN, this is will clear any ownership flag se
This returns a value which can be checked with the macro SWIG_IsOK()
</div>
<p><tt>void SWIG_NewPointerObj(lua_State* L,void* ptr,swig_type_info *type,int own);</tt></p>
<p><tt>void SWIG_NewPointerObj(lua_State* L, void* ptr, swig_type_info *type, int own);</tt></p>
<div class="indent">
This is the opposite of SWIG_ConvertPtr, as it pushes a new userdata which wrappers the pointer 'ptr' of type 'type'.
The parameter 'own' specifies if the object is owned be Lua and if it is 1 then Lua will GC the object when the userdata is disposed of.
</div>
<p><tt>void* SWIG_MustGetPtr(lua_State* L,int index,swig_type_info *type,int flags,int argnum,const char* func_name);</tt></p>
<p><tt>void* SWIG_MustGetPtr(lua_State* L, int index, swig_type_info *type, int flags, int argnum, const char* func_name);</tt></p>
<div class="indent">
This function is a version of SWIG_ConvertPtr(), except that it will either work, or it will trigger a lua_error() with a text error message. This function is rarely used, and may be deprecated in the future.
@ -1762,11 +1762,11 @@ This function is a version of SWIG_ConvertPtr(), except that it will either work
This macro, when called within the context of a SWIG wrapped function, will jump to the error handler code. This will call any cleanup code (freeing any temp variables) and then triggers a lua_error.<br>
A common use for this code is:<br><pre>
if (!SWIG_IsOK(SWIG_ConvertPtr( .....)){
lua_pushstring(L,"something bad happened");
lua_pushstring(L, "something bad happened");
SWIG_fail;
}</pre></div>
<p><tt>SWIG_fail_arg(char* func_name,int argnum,char* type)</tt></p>
<p><tt>SWIG_fail_arg(char* func_name, int argnum, char* type)</tt></p>
<div class="indent">
This macro, when called within the context of a SWIG wrapped function, will display the error message and jump to the error handler code. The error message is of the form
@ -1774,7 +1774,7 @@ This macro, when called within the context of a SWIG wrapped function, will disp
"Error in <i>func_name</i> (arg <i>argnum</i>), expected '<i>type</i>' got '<i>whatever the type was</i>'"
</pre></div>
<p><tt>SWIG_fail_ptr(const char* fn_name,int argnum,swig_type_info* type);</tt></p>
<p><tt>SWIG_fail_ptr(const char* fn_name, int argnum, swig_type_info* type);</tt></p>
<div class="indent">
Similar to SWIG_fail_arg, except that it will display the swig_type_info information instead.</div>
@ -1878,24 +1878,24 @@ At initialisation time, it will then add to the interpreter a table called 'exam
&gt; print(example)
table: 003F8F90
&gt; m=getmetatable(example)
&gt; table.foreach(m,print)
&gt; table.foreach(m, print)
.set table: 003F9088
.get table: 003F9038
__index function: 003F8FE0
__newindex function: 003F8FF8
&gt; g=m['.get']
&gt; table.foreach(g,print)
&gt; table.foreach(g, print)
Foo function: 003FAFD8
&gt;
</pre></div>
<p>
The .get and .set tables are lookups connecting the variable name 'Foo' to the accessor/mutator functions (Foo_set,Foo_get)
The .get and .set tables are lookups connecting the variable name 'Foo' to the accessor/mutator functions (Foo_set, Foo_get)
</p>
<p>
The Lua equivalent of the code for the <tt>__index</tt> and <tt>__newindex</tt> looks a bit like this
</p>
<div class="targetlang"><pre>
function __index(mod,name)
function __index(mod, name)
local g=getmetatable(mod)['.get'] -- gets the table
if not g then return nil end
local f=g[name] -- looks for the function
@ -1904,13 +1904,13 @@ function __index(mod,name)
return nil
end
function __newindex(mod,name,value)
function __newindex(mod, name, value)
local s=getmetatable(mod)['.set'] -- gets the table
if not s then return end
local f=s[name] -- looks for the function
-- calls it to set the value
if type(f)=="function" then f(value)
else rawset(mod,name,value) end
else rawset(mod, name, value) end
end
</pre></div>
<p>
@ -1933,10 +1933,10 @@ Given a class
class Point
{
public:
int x,y;
int x, y;
Point(){x=y=0;}
~Point(){}
virtual void Print(){printf("Point @%p (%d,%d)\n",this,x,y);}
virtual void Print(){printf("Point @%p (%d, %d)\n", this, x, y);}
};
</pre></div>
<p>
@ -1950,7 +1950,7 @@ Some of the internals can be seen by looking at the metatable of a class:
&gt; print(p)
userdata: 003FDB28
&gt; m=getmetatable(p)
&gt; table.foreach(m,print)
&gt; table.foreach(m, print)
.type Point
__gc function: 003FB6C8
__newindex function: 003FB6B0
@ -1966,7 +1966,7 @@ The '.type' attribute is the name of the class. The '.get' and '.set' tables wor
The Lua equivalent of the code for enabling functions looks a little like this
</p>
<div class="targetlang"><pre>
function __index(obj,name)
function __index(obj, name)
local m=getmetatable(obj) -- gets the metatable
if not m then return nil end
local g=m['.get'] -- gets the attribute table

View file

@ -684,7 +684,7 @@ consist of the following parts:
</tr>
<tr>
<td>m3wrapfreearg</td>
<td><tt>M3toC.FreeSharedS(str,arg1);</tt></td>
<td><tt>M3toC.FreeSharedS(str, arg1);</tt></td>
<td>
Free resources that were temporarily used in the wrapper.
Since this step should never be skipped,
@ -858,7 +858,7 @@ where almost everything is generated by a typemap:
RAISE E("invalid checksum");
END;
FINALLY
M3toC.FreeSharedS(str,arg1); <I>(* m3wrapfreearg *)</I>
M3toC.FreeSharedS(str, arg1); <I>(* m3wrapfreearg *)</I>
END;
END Name;
</pre></div>
@ -891,7 +891,7 @@ where almost everything is generated by a typemap:
<tr>
<td>constnumeric</td>
<td><tt>%constnumeric(12) twelve;</tt> or
<tt>%feature("constnumeric","12") twelve;</tt></td>
<tt>%feature("constnumeric", "12") twelve;</tt></td>
<td>This feature can be used to tell Modula-3's back-end of SWIG
the value of an identifier.
This is necessary in the cases

View file

@ -44,7 +44,7 @@ The general form of this directive is:
</p>
<div class="code"><pre>
<tt>%module(option1="value1",option2="value2",...) modulename</tt>
<tt>%module(option1="value1", option2="value2", ...) modulename</tt>
</pre></div>
<p>

Some files were not shown because too many files have changed in this diff Show more