Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
SRCS = example.c
include $(SRCDIR)../example.mk

View File

@@ -0,0 +1,21 @@
/* File : example.c */
/* A global variable */
double Foo = 3.0;
/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
int g;
g = y;
while (x > 0) {
g = x;
x = y % x;
y = g;
}
return g;
}
int fact(int n) {
if (n <= 0) return 1;
return n*fact(n-1);
}

View File

@@ -0,0 +1,23 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
%contract gcd(int x, int y) {
require:
x >= 0;
y >= 0;
}
%contract fact(int n) {
require:
n >= 0;
ensure:
fact >= 1;
}
%inline %{
extern int gcd(int x, int y);
extern int fact(int n);
extern double Foo;
%}

View File

@@ -0,0 +1,24 @@
# do not dump Octave core
if exist("crash_dumps_octave_core", "builtin")
crash_dumps_octave_core(0);
endif
swigexample
# Call our gcd() function
x = 42;
y = 105;
g = swigexample.gcd(x,y);
printf("The gcd of %d and %d is %d\n",x,y,g);
# Manipulate the Foo global variable
# Output its current value
printf("Foo = %f\n", swigexample.cvar.Foo);
# Change its value
swigexample.cvar.Foo = 3.1415926;
# See if the change took effect
printf("Foo = %f\n", swigexample.cvar.Foo);