diff options
Diffstat (limited to 'Examples/pike/simple')
| -rw-r--r-- | Examples/pike/simple/Makefile | 18 | ||||
| -rw-r--r-- | Examples/pike/simple/example.c | 18 | ||||
| -rw-r--r-- | Examples/pike/simple/example.i | 7 | ||||
| -rw-r--r-- | Examples/pike/simple/runme.pike | 20 |
4 files changed, 63 insertions, 0 deletions
diff --git a/Examples/pike/simple/Makefile b/Examples/pike/simple/Makefile new file mode 100644 index 0000000..544c97b --- /dev/null +++ b/Examples/pike/simple/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.c +TARGET = example +INTERFACE = example.i + +all: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike + +static: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static + +clean: + $(MAKE) -f $(TOP)/Makefile pike_clean + +check: all diff --git a/Examples/pike/simple/example.c b/Examples/pike/simple/example.c new file mode 100644 index 0000000..1c2af78 --- /dev/null +++ b/Examples/pike/simple/example.c @@ -0,0 +1,18 @@ +/* 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; +} + + diff --git a/Examples/pike/simple/example.i b/Examples/pike/simple/example.i new file mode 100644 index 0000000..24093b9 --- /dev/null +++ b/Examples/pike/simple/example.i @@ -0,0 +1,7 @@ +/* File : example.i */ +%module example + +%inline %{ +extern int gcd(int x, int y); +extern double Foo; +%} diff --git a/Examples/pike/simple/runme.pike b/Examples/pike/simple/runme.pike new file mode 100644 index 0000000..a6a78e9 --- /dev/null +++ b/Examples/pike/simple/runme.pike @@ -0,0 +1,20 @@ +int main() +{ + /* Call our gcd() function */ + int x = 42; + int y = 105; + int g = .example.gcd(x, y); + write("The gcd of %d and %d is %d\n", x, y, g); + + /* Manipulate the Foo global variable */ + /* Output its current value */ + write("Foo = %f\n", .example->Foo_get()); + + /* Change its value */ + .example->Foo_set(3.1415926); + + /* See if the change took effect */ + write("Foo = %f\n", .example->Foo_get()); + + return 0; +} |
