createProxyRCall: Generate C routine to act as proxy for a C routine pointer

Description Usage Arguments Value Author(s) Examples

Description

This function is used to create C code that one can use as a function pointer as a callback which will in turn call an R function. This allows an R programmer to provide an R function where a C routine is expected.

Usage

1
createProxyRCall(func, name, functionVar = paste("R", name, "function_var", sep = "_"), preamble = character(), typeMap = list())

Arguments

func

a FunctionPointer object that provides the description of the C routine for which we want to create a proxy which will call an R function.

name

the name of the new C routine being created.

functionVar

a string the provides C code which is used to obtain the R function to call. This might be to cast an argument of the routine, access a global variable, or a call to a C routine which will return a SEXP.

preamble

additional code that is inserted into the generated C routine at the end of the declarations but before the calls.

typeMap

mappings from C types to converters between R and C and providing corresponding variable types in the different languages.

Value

a CRoutineDefinition object containing the generated C routine code.

Author(s)

Duncan Temple Lang

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    # 
    #  Create the description of a C routine that returns an integer
    #  and accepts 2 parameters - an integer and a double.
    # 
  funDef = new("FunctionPointer", 
                  returnType = new("intType"),
                  parameters = list(new("Parameter", name = "a", type = new("intType")),
                                    new("Parameter", name = "b", type = new("doubleType"))))

  funDef

      # now create the proxy routine that would call an R function.
  code = createProxyRCall(funDef, "foo")
  print(code)

## Not run: 
      #XXX  correct the name of the doubleType for the pointer in the createNativeReference.
  funDef = new("FunctionPointer", 
                  returnType = new("intType"),
                  parameters = list(new("Parameter", name = "a", type = new("intType")),
                                    new("Parameter", name = "b", type = new("PointerType", type = new("doubleType", name = "double")))))

## End(Not run)

omegahat/RGCCTranslationUnit documentation built on May 24, 2019, 1:53 p.m.