Committing R-SWIG

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9175 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Joseph Wang 2006-06-29 03:01:18 +00:00
commit 3a821460fe
51 changed files with 5154 additions and 9 deletions

View file

@ -0,0 +1,16 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
ARGS = SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)'
all::
$(MAKE) -f $(TOP)/Makefile $(ARGS) r
clean::
$(MAKE) -f $(TOP)/Makefile $(ARGS) r_clean
check: all
R CMD BATCH runme.R

View file

@ -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;
}

View file

@ -0,0 +1,7 @@
/* File : example.i */
%module example
%inline %{
extern int gcd(int x, int y);
extern double Foo;
%}

View file

@ -0,0 +1,24 @@
# file: runme.R
dyn.load('example_wrap.so')
source('example_wrap.R')
cacheMetaData(1)
# Call our gcd() function
x <- 42
y <- 105
g <- gcd(x,y)
sprintf("The gcd of %d and %d is %d", x, y, g)
# Manipulate the Foo global variable
# Output its current value
Foo()
# Change its value
Foo(3.1415926)
# See if the change took effect
Foo()