*** empty log message ***
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@50 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
ad3d48ca15
commit
63880a6e34
16 changed files with 517 additions and 0 deletions
17
Examples/perl5/simple/Makefile
Normal file
17
Examples/perl5/simple/Makefile
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
SWIGOPT =
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.o core *~ *.so *.pm myperl
|
||||
|
||||
1
Examples/perl5/simple/README
Normal file
1
Examples/perl5/simple/README
Normal file
|
|
@ -0,0 +1 @@
|
|||
Simple example from users manual.
|
||||
24
Examples/perl5/simple/example.c
Normal file
24
Examples/perl5/simple/example.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* Simple example from documentation */
|
||||
/* File : example.c */
|
||||
|
||||
#include <time.h>
|
||||
|
||||
double My_variable = 3.0;
|
||||
|
||||
/* Compute factorial of n */
|
||||
int fact(int n) {
|
||||
if (n <= 1) return 1;
|
||||
else return n*fact(n-1);
|
||||
}
|
||||
|
||||
/* Compute n mod m */
|
||||
int my_mod(int n, int m) {
|
||||
return (n % m);
|
||||
}
|
||||
|
||||
|
||||
char *get_time() {
|
||||
long ltime;
|
||||
time(<ime);
|
||||
return ctime(<ime);
|
||||
}
|
||||
11
Examples/perl5/simple/example.i
Normal file
11
Examples/perl5/simple/example.i
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%{
|
||||
/* Put headers and other declarations here */
|
||||
%}
|
||||
|
||||
|
||||
extern double My_variable;
|
||||
extern int fact(int);
|
||||
%name(mod) extern int my_mod(int n, int m);
|
||||
extern char *get_time();
|
||||
23
Examples/perl5/simple/example.pl
Executable file
23
Examples/perl5/simple/example.pl
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# Perl5 script for testing simple example
|
||||
|
||||
use example;
|
||||
package example;
|
||||
|
||||
print get_time();
|
||||
print "My Variable = $My_variable","\n";
|
||||
for ($i = 0; $i < 14; $i++) {
|
||||
$n = fact($i);
|
||||
print "$i factorial is $n\n";
|
||||
}
|
||||
|
||||
for ($i = 1; $i < 250; $i++) {
|
||||
for ($j = 1; $j < 250; $j++) {
|
||||
$n = mod($i,$j);
|
||||
$My_variable = $My_variable + $n;
|
||||
}
|
||||
}
|
||||
|
||||
print "My_variable = ", $My_variable, "\n";
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue