All the runtime scripts are called runme.pl now for easier testing
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5652 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d2d3496881
commit
6f2e85b5c2
22 changed files with 31 additions and 20 deletions
|
|
@ -90,7 +90,7 @@ Note: when creating a C++ extension, you must run SWIG with the <tt>-c++</tt> op
|
|||
|
||||
<h2>A sample Perl script</h2>
|
||||
|
||||
Click <a href="example.pl">here</a> to see a script that calls the C++ functions from Perl.
|
||||
Click <a href="runme.pl">here</a> to see a script that calls the C++ functions from Perl.
|
||||
|
||||
<h2>Key points</h2>
|
||||
|
||||
|
|
|
|||
57
SWIG/Examples/perl5/class/runme.pl
Normal file
57
SWIG/Examples/perl5/class/runme.pl
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# file: runme.pl
|
||||
|
||||
# This file illustrates the low-level C++ interface
|
||||
# created by SWIG. In this case, all of our C++ classes
|
||||
# get converted into function calls.
|
||||
|
||||
use example;
|
||||
|
||||
# ----- Object creation -----
|
||||
|
||||
print "Creating some objects:\n";
|
||||
$c = examplec::new_Circle(10);
|
||||
print " Created circle $c\n";
|
||||
$s = examplec::new_Square(10);
|
||||
print " Created square $s\n";
|
||||
|
||||
# ----- Access a static member -----
|
||||
|
||||
print "\nA total of $examplec::Shape_nshapes shapes were created\n";
|
||||
|
||||
# ----- Member data access -----
|
||||
|
||||
# Set the location of the object.
|
||||
# Note: methods in the base class Shape are used since
|
||||
# x and y are defined there.
|
||||
|
||||
examplec::Shape_x_set($c, 20);
|
||||
examplec::Shape_y_set($c, 30);
|
||||
examplec::Shape_x_set($s,-10);
|
||||
examplec::Shape_y_set($s,5);
|
||||
|
||||
print "\nHere is their current position:\n";
|
||||
print " Circle = (",examplec::Shape_x_get($c),",", examplec::Shape_y_get($c),")\n";
|
||||
print " Square = (",examplec::Shape_x_get($s),",", examplec::Shape_y_get($s),")\n";
|
||||
|
||||
# ----- Call some methods -----
|
||||
|
||||
print "\nHere are some properties of the shapes:\n";
|
||||
foreach $o ($c,$s) {
|
||||
print " $o\n";
|
||||
print " area = ", examplec::Shape_area($o), "\n";
|
||||
print " perimeter = ", examplec::Shape_perimeter($o), "\n";
|
||||
}
|
||||
# Notice how the Shape_area() and Shape_perimeter() functions really
|
||||
# invoke the appropriate virtual method on each object.
|
||||
|
||||
# ----- Delete everything -----
|
||||
|
||||
print "\nGuess I'll clean up now\n";
|
||||
|
||||
# Note: this invokes the virtual destructor
|
||||
examplec::delete_Shape($c);
|
||||
examplec::delete_Shape($s);
|
||||
|
||||
print $examplec::Shape_nshapes," shapes remain\n";
|
||||
print "Goodbye\n";
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ to see a SWIG interface with some constant declarations in it.
|
|||
|
||||
<h2>Accessing Constants from Perl</h2>
|
||||
|
||||
Click <a href="example.pl">here</a> to see a script that prints out the values
|
||||
Click <a href="runme.pl">here</a> to see a script that prints out the values
|
||||
of the constants contained in the above file.
|
||||
|
||||
<h2>Key points</h2>
|
||||
|
|
|
|||
29
SWIG/Examples/perl5/constants/runme.pl
Normal file
29
SWIG/Examples/perl5/constants/runme.pl
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# file: runme.pl
|
||||
|
||||
use example;
|
||||
|
||||
print "ICONST = ", $example::ICONST, " (should be 42)\n";
|
||||
print "FCONST = ", $example::FCONST, " (should be 2.1828)\n";
|
||||
print "CCONST = ", $example::CCONST, " (should be 'x')\n";
|
||||
print "CCONST2 = ", $example::CCONST2," (this should be on a new line)\n";
|
||||
print "SCONST = ", $example::SCONST, " (should be 'Hello World')\n";
|
||||
print "SCONST2 = ", $example::SCONST2, " (should be '\"Hello World\"')\n";
|
||||
print "EXPR = ", $example::EXPR, " (should be 48.5484)\n";
|
||||
print "iconst = ", $example::iconst, " (should be 37)\n";
|
||||
print "fconst = ", $example::fconst, " (should be 3.14)\n";
|
||||
|
||||
|
||||
if ($example::EXTERN) {
|
||||
print "EXTERN = ", example.EXTERN, " (Arg! This shouldn't print anything)\n";
|
||||
} else {
|
||||
print "EXTERN isn't defined (good)\n";
|
||||
}
|
||||
|
||||
if ($example::FOO) {
|
||||
print "FOO = ", example.FOO, "(Arg! This shouldn't print anything)\n";
|
||||
} else {
|
||||
print "FOO isn't defined (good)\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
16
SWIG/Examples/perl5/constants2/runme.pl
Normal file
16
SWIG/Examples/perl5/constants2/runme.pl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# file: runme.pl
|
||||
|
||||
use example;
|
||||
|
||||
print "ICONST = ", example::ICONST, " (should be 42)\n";
|
||||
print "FCONST = ", example::FCONST, " (should be 2.1828)\n";
|
||||
print "CCONST = ", example::CCONST, " (should be 'x')\n";
|
||||
print "CCONST2 = ", example::CCONST2," (this should be on a new line)\n";
|
||||
print "SCONST = ", example::SCONST, " (should be 'Hello World')\n";
|
||||
print "SCONST2 = ", example::SCONST2, " (should be '\"Hello World\"')\n";
|
||||
print "EXPR = ", example::EXPR, " (should be 48.5484)\n";
|
||||
print "iconst = ", example::iconst, " (should be 37)\n";
|
||||
print "fconst = ", example::fconst, " (should be 3.14)\n";
|
||||
|
||||
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ Here are some files that illustrate this with a simple example:
|
|||
<li><a href="example.c">example.c</a>
|
||||
<li><a href="example.h">example.h</a>
|
||||
<li><a href="example.i">example.i</a> (SWIG interface)
|
||||
<li><a href="example.pl">example.pl</a> (Sample script)
|
||||
<li><a href="runme.pl">runme.pl</a> (Sample script)
|
||||
</ul>
|
||||
|
||||
<h2>Notes</h2>
|
||||
|
|
|
|||
21
SWIG/Examples/perl5/funcptr/runme.pl
Normal file
21
SWIG/Examples/perl5/funcptr/runme.pl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# file: runme.pl
|
||||
|
||||
use example;
|
||||
|
||||
$a = 37;
|
||||
$b = 42;
|
||||
|
||||
# Now call our C function with a bunch of callbacks
|
||||
|
||||
print "Trying some C callback functions\n";
|
||||
print " a = $a\n";
|
||||
print " b = $b\n";
|
||||
print " ADD(a,b) = ", example::do_op($a,$b,$example::ADD),"\n";
|
||||
print " SUB(a,b) = ", example::do_op($a,$b,$example::SUB),"\n";
|
||||
print " MUL(a,b) = ", example::do_op($a,$b,$example::MUL),"\n";
|
||||
|
||||
print "Here is what the C callback function objects look like in Perl\n";
|
||||
print " ADD = $example::ADD\n";
|
||||
print " SUB = $example::SUB\n";
|
||||
print " MUL = $example::MUL\n";
|
||||
|
||||
|
|
@ -3,6 +3,7 @@ example.pm
|
|||
foo.pm
|
||||
bar.pm
|
||||
spam.pm
|
||||
bar.plg
|
||||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.dll
|
||||
|
|
|
|||
10
SWIG/Examples/perl5/mpointer/.cvsignore
Normal file
10
SWIG/Examples/perl5/mpointer/.cvsignore
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
example.pm
|
||||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
example.dll
|
||||
example.dsw
|
||||
example.ncb
|
||||
example.opt
|
||||
example.plg
|
||||
Release
|
||||
Debug
|
||||
28
SWIG/Examples/perl5/multimap/runme.pl
Normal file
28
SWIG/Examples/perl5/multimap/runme.pl
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# file: runme.pl
|
||||
|
||||
use example;
|
||||
|
||||
# Call our gcd() function
|
||||
|
||||
$x = 42;
|
||||
$y = 105;
|
||||
$g = example::gcd($x,$y);
|
||||
print "The gcd of $x and $y is $g\n";
|
||||
|
||||
# Call the gcdmain() function
|
||||
@a = ("gcdmain","42","105");
|
||||
example::gcdmain(\@a);
|
||||
|
||||
# Call the count function
|
||||
print example::count("Hello World", "l"),"\n";
|
||||
|
||||
# Call the capitize function
|
||||
|
||||
print example::capitalize("hello world"),"\n";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -147,7 +147,7 @@ extraction.
|
|||
<ul>
|
||||
<li> <a href="example.c">example.c</a> (C Source)
|
||||
<li> <a href="example.i">example.i</a> (Swig interface)
|
||||
<li> <a href="example.pl">example.pl</a> (Perl Script)
|
||||
<li> <a href="runme.pl">runme.pl</a> (Perl Script)
|
||||
</ul>
|
||||
|
||||
<h2>Notes</h2>
|
||||
|
|
|
|||
44
SWIG/Examples/perl5/pointer/runme.pl
Normal file
44
SWIG/Examples/perl5/pointer/runme.pl
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# file: runme.pl
|
||||
|
||||
use example;
|
||||
|
||||
# First create some objects using the pointer library.
|
||||
print "Testing the pointer library\n";
|
||||
$a = example::new_intp();
|
||||
$b = example::new_intp();
|
||||
$c = example::new_intp();
|
||||
example::intp_assign($a,37);
|
||||
example::intp_assign($b,42);
|
||||
|
||||
print " a = $a\n";
|
||||
print " b = $b\n";
|
||||
print " c = $c\n";
|
||||
|
||||
# Call the add() function with some pointers
|
||||
example::add($a,$b,$c);
|
||||
|
||||
# Now get the result
|
||||
$r = example::intp_value($c);
|
||||
print " 37 + 42 = $r\n";
|
||||
|
||||
# Clean up the pointers
|
||||
example::delete_intp($a);
|
||||
example::delete_intp($b);
|
||||
example::delete_intp($c);
|
||||
|
||||
# Now try the typemap library
|
||||
# This should be much easier. Now how it is no longer
|
||||
# necessary to manufacture pointers.
|
||||
|
||||
print "Trying the typemap library\n";
|
||||
$r = example::sub(37,42);
|
||||
print " 37 - 42 = $r\n";
|
||||
|
||||
# Now try the version with multiple return values
|
||||
|
||||
print "Testing multiple return values\n";
|
||||
($q,$r) = example::divide(42,37);
|
||||
print " 42/37 = $q remainder $r\n";
|
||||
|
||||
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ Click <a href="example.i">here</a> to see a SWIG interface file with these addit
|
|||
|
||||
<h2>Sample Perl script</h2>
|
||||
|
||||
Click <a href="example.pl">here</a> to see a script that manipulates some C++ references.
|
||||
Click <a href="runme.pl">here</a> to see a script that manipulates some C++ references.
|
||||
|
||||
<h2>Notes:</h2>
|
||||
|
||||
|
|
|
|||
74
SWIG/Examples/perl5/reference/runme.pl
Normal file
74
SWIG/Examples/perl5/reference/runme.pl
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# file: runme.pl
|
||||
|
||||
# This file illustrates the manipulation of C++ references in Perl.
|
||||
# This uses the low-level interface. Shadow classes work differently.
|
||||
|
||||
use example;
|
||||
|
||||
# ----- Object creation -----
|
||||
|
||||
print "Creating some objects:\n";
|
||||
$a = example::new_Vector(3,4,5);
|
||||
$b = example::new_Vector(10,11,12);
|
||||
|
||||
print " Created",example::Vector_print($a),"\n";
|
||||
print " Created",example::Vector_print($b),"\n";
|
||||
|
||||
# ----- Call an overloaded operator -----
|
||||
|
||||
# This calls the wrapper we placed around
|
||||
#
|
||||
# operator+(const Vector &a, const Vector &)
|
||||
#
|
||||
# It returns a new allocated object.
|
||||
|
||||
print "Adding a+b\n";
|
||||
$c = example::addv($a,$b);
|
||||
print " a+b =", example::Vector_print($c),"\n";
|
||||
|
||||
# Note: Unless we free the result, a memory leak will occur
|
||||
example::delete_Vector($c);
|
||||
|
||||
# ----- Create a vector array -----
|
||||
|
||||
# Note: Using the high-level interface here
|
||||
print "Creating an array of vectors\n";
|
||||
$va = example::new_VectorArray(10);
|
||||
print " va = $va\n";
|
||||
|
||||
# ----- Set some values in the array -----
|
||||
|
||||
# These operators copy the value of $a and $b to the vector array
|
||||
example::VectorArray_set($va,0,$a);
|
||||
example::VectorArray_set($va,1,$b);
|
||||
|
||||
# This will work, but it will cause a memory leak!
|
||||
|
||||
example::VectorArray_set($va,2,example::addv($a,$b));
|
||||
|
||||
# The non-leaky way to do it
|
||||
|
||||
$c = example::addv($a,$b);
|
||||
example::VectorArray_set($va,3,$c);
|
||||
example::delete_Vector($c);
|
||||
|
||||
# Get some values from the array
|
||||
|
||||
print "Getting some array values\n";
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
print " va($i) = ", example::Vector_print(example::VectorArray_get($va,$i)), "\n";
|
||||
}
|
||||
|
||||
# Watch under resource meter to check on this
|
||||
print "Making sure we don't leak memory.\n";
|
||||
for ($i = 0; $i < 1000000; $i++) {
|
||||
$c = example::VectorArray_get($va,$i % 10);
|
||||
}
|
||||
|
||||
# ----- Clean up -----
|
||||
print "Cleaning up\n";
|
||||
|
||||
example::delete_VectorArray($va);
|
||||
example::delete_Vector($a);
|
||||
example::delete_Vector($b);
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ Note: when creating a C++ extension, you must run SWIG with the <tt>-c++</tt> op
|
|||
|
||||
<h2>A sample Perl script</h2>
|
||||
|
||||
Click <a href="example.pl">here</a> to see a script that calls the C++ functions from Perl.
|
||||
Click <a href="runme.pl">here</a> to see a script that calls the C++ functions from Perl.
|
||||
|
||||
<h2>Key points</h2>
|
||||
|
||||
|
|
|
|||
56
SWIG/Examples/perl5/shadow/runme.pl
Normal file
56
SWIG/Examples/perl5/shadow/runme.pl
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# file: runme.pl
|
||||
|
||||
# This file illustrates the low-level C++ interface
|
||||
# created by SWIG. In this case, all of our C++ classes
|
||||
# get converted into function calls.
|
||||
|
||||
use example;
|
||||
|
||||
# ----- Object creation -----
|
||||
|
||||
print "Creating some objects:\n";
|
||||
$c = new example::Circle(10);
|
||||
print " Created circle $c\n";
|
||||
$s = new example::Square(10);
|
||||
print " Created square $s\n";
|
||||
|
||||
# ----- Access a static member -----
|
||||
|
||||
print "\nA total of $example::Shape::nshapes shapes were created\n";
|
||||
|
||||
# ----- Member data access -----
|
||||
|
||||
# Set the location of the object.
|
||||
# Note: methods in the base class Shape are used since
|
||||
# x and y are defined there.
|
||||
|
||||
$c->{x} = 20;
|
||||
$c->{y} = 30;
|
||||
$s->{x} = -10;
|
||||
$s->{y} = 5;
|
||||
|
||||
print "\nHere is their current position:\n";
|
||||
print " Circle = (",$c->{x},",", $c->{y},")\n";
|
||||
print " Square = (",$s->{x},",", $s->{y},")\n";
|
||||
|
||||
# ----- Call some methods -----
|
||||
|
||||
print "\nHere are some properties of the shapes:\n";
|
||||
foreach $o ($c,$s) {
|
||||
print " $o\n";
|
||||
print " area = ", $o->area(), "\n";
|
||||
print " perimeter = ", $o->perimeter(), "\n";
|
||||
}
|
||||
|
||||
# ----- Delete everything -----
|
||||
|
||||
print "\nGuess I'll clean up now\n";
|
||||
|
||||
# Note: this invokes the virtual destructor
|
||||
|
||||
$c->DESTROY();
|
||||
$s->DESTROY();
|
||||
|
||||
print $example::Shape::nshapes," shapes remain\n";
|
||||
print "Goodbye\n";
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ to create the extension <tt>example.so</tt>.
|
|||
|
||||
<h2>Using the extension</h2>
|
||||
|
||||
Click <a href="example.pl">here</a> to see a script that calls our C functions from Perl.
|
||||
Click <a href="runme.pl">here</a> to see a script that calls our C functions from Perl.
|
||||
|
||||
<h2>Key points</h2>
|
||||
|
||||
|
|
|
|||
23
SWIG/Examples/perl5/simple/runme.pl
Normal file
23
SWIG/Examples/perl5/simple/runme.pl
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# Perl5 script for testing simple example
|
||||
|
||||
use example;
|
||||
|
||||
# Call our gcd() function
|
||||
|
||||
$x = 42;
|
||||
$y = 105;
|
||||
$g = example::gcd($x,$y);
|
||||
print "The gcd of $x and $y is $g\n";
|
||||
|
||||
# Manipulate the Foo global variable
|
||||
|
||||
# Output its current value
|
||||
print "Foo = $example::Foo\n";
|
||||
|
||||
# Change its value
|
||||
$example::Foo = 3.1415926;
|
||||
|
||||
# See if the change took effect
|
||||
print "Foo = $example::Foo\n";
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ objects and to print out the value (for debugging purposes).
|
|||
|
||||
<h2>A Perl Script</h2>
|
||||
|
||||
Click <a href="example.pl">here</a> to see a script that uses these functions from Perl.
|
||||
Click <a href="runme.pl">here</a> to see a script that uses these functions from Perl.
|
||||
|
||||
<h2>Notes</h2>
|
||||
|
||||
|
|
|
|||
38
SWIG/Examples/perl5/value/runme.pl
Normal file
38
SWIG/Examples/perl5/value/runme.pl
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# file: runme.pl
|
||||
|
||||
use example;
|
||||
|
||||
# Create a couple of a vectors
|
||||
|
||||
$v = example::new_Vector(1,2,3);
|
||||
$w = example::new_Vector(10,11,12);
|
||||
|
||||
print "I just created the following vectors\n";
|
||||
example::vector_print($v);
|
||||
example::vector_print($w);
|
||||
|
||||
# Now call some of our functions
|
||||
|
||||
print "\nNow I'm going to compute the dot product\n";
|
||||
$d = example::dot_product($v,$w);
|
||||
print "dot product = $d (should be 68)\n";
|
||||
|
||||
# Add the vectors together
|
||||
|
||||
print "\nNow I'm going to add the vectors together\n";
|
||||
$r = example::vector_add($v,$w);
|
||||
example::vector_print($r);
|
||||
print "The value should be (11,13,15)\n";
|
||||
|
||||
# Now I'd better clean up the return result r
|
||||
|
||||
print "\nNow I'm going to clean up the return result\n";
|
||||
example::free($r);
|
||||
|
||||
print "Good\n";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue