More consistent formatting of examples in documentation

This commit is contained in:
William S Fulton 2017-07-30 13:41:45 +01:00
commit 7ee76f93f9
9 changed files with 96 additions and 99 deletions

View file

@ -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-&gt;re(), this-&gt;im()); sprintf(buffer, "Complex(%g, %g)", this-&gt;re(), this-&gt;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

View file

@ -226,13 +226,12 @@ resulting C file should be built as a python extension, inserting the module
#include "example.h" #include "example.h"
int fact(int n) { int fact(int n) {
if (n &lt; 0){ /* This should probably return an error, but this is simpler */ if (n &lt; 0) { /* This should probably return an error, but this is simpler */
return 0; return 0;
} }
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);
} }