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:
parent
bf06e16ce4
commit
3a821460fe
51 changed files with 5154 additions and 9 deletions
16
SWIG/Examples/r/simple/Makefile
Normal file
16
SWIG/Examples/r/simple/Makefile
Normal 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
|
||||
18
SWIG/Examples/r/simple/example.c
Normal file
18
SWIG/Examples/r/simple/example.c
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
7
SWIG/Examples/r/simple/example.i
Normal file
7
SWIG/Examples/r/simple/example.i
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%inline %{
|
||||
extern int gcd(int x, int y);
|
||||
extern double Foo;
|
||||
%}
|
||||
24
SWIG/Examples/r/simple/runme.R
Normal file
24
SWIG/Examples/r/simple/runme.R
Normal 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()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue