More consistent formatting of examples in documentation
This commit is contained in:
parent
8753f9652c
commit
7ee76f93f9
9 changed files with 96 additions and 99 deletions
|
|
@ -1008,8 +1008,7 @@ The following operators cannot be overloaded (mainly because they are not suppor
|
||||||
<p>
|
<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
|
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>
|
</p>
|
||||||
<div class="code"><pre>const char* __str__()
|
<div class="code"><pre>const char* __str__() {
|
||||||
{
|
|
||||||
static char buffer[255];
|
static char buffer[255];
|
||||||
sprintf(buffer, "Complex(%g, %g)", this->re(), this->im());
|
sprintf(buffer, "Complex(%g, %g)", this->re(), this->im());
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
@ -1031,8 +1030,7 @@ Complex(10, 12)
|
||||||
<p>
|
<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>
|
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>
|
||||||
</p>
|
</p>
|
||||||
<div class="code"><pre>class Complex
|
<div class="code"><pre>class Complex {
|
||||||
{
|
|
||||||
//....
|
//....
|
||||||
double __getitem__(int i)const; // i is the index, returns the data
|
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
|
||||||
|
|
|
||||||
|
|
@ -231,8 +231,7 @@ int fact(int n) {
|
||||||
}
|
}
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
/* testing for overflow would be a good idea here */
|
/* testing for overflow would be a good idea here */
|
||||||
return n * fact(n-1);
|
return n * fact(n-1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue