comparison R/rdyncall/demo/callbacks.R @ 0:0cfcc391201f

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:26:28 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0cfcc391201f
1 # Package: rdyncall
2 # File: demo/callbacks.R
3 # Description: Creating a callback and call it via .dyncall
4
5 # The function to wrap:
6 f <- function(x,y) x+y
7
8 # Create the callback:
9 cb <- new.callback("ii)i", f)
10
11 # Call the callback
12 r <- .dyncall(cb, "ii)i", 20, 3)
13 r == 23
14
15 # Recursive callback example:
16
17 f <- function(x,y,f,i)
18 {
19 if (i > 1) .dyncall(f, "iipi)i", x,y,f,i-1)
20 x+y
21 }
22
23 cb <- new.callback("iipi)i", f)
24
25 r <- .dyncall(cb, "iipi)i", 1,1,cb,100 )
26 r == 2
27