Description Usage Arguments Value Author(s) References See Also Examples
This function and its methods generate the R code
to interface to a C-level struct. It creates
classes to parallel the struct in R or to
maintain a reference to a C-level instance of the struct.
It generates methods for $
and [[
to access fields within a reference to the struct,
and also a method for the names
function to return the
names of the fields for a reference to a C instance of the struct.
The function provides coercion methods from a reference to the R representation
(by copying the fields into slots in the R object),
and from a simple pointer to the R classes (reference and R-level
representation).
This also creates a constructor function to create an instance of the
R-level class.
The function also creates an FFI description of the structure
for use with accessing the individual fields or specifying
the struct as an input or output type of a C routine
so that the routine can be invoked via callCIF
.
1 2 3 |
type |
the GCC TU description of the C struct type. This must be resolved |
name |
the name of the structure |
ref |
whether to create code for the reference class |
refClassName |
the name of the reference class. By default we append Ref to the end of the name of the regular R representation class. |
useGlobalFFIType |
a logical value controlling whether we put the FFI description of the struct in a global variable and refer to that or put it in a closure to be used locally within each function. |
useClosure |
a logical value controlling whether to create functions with their own environments so that they can refer to the FFI type and symbol addresses locally rather than polluting the search path. |
A list with code for the different aspects of the interface.
defs |
class definitions |
dollar |
for the |
coerce |
coercion code, i.e. the as methods |
constructors |
code for the constructor function |
names |
function returing the field names of a reference to the struct |
Duncan Temple Lang
The RGCCTranslationUnit. libffi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | tu.file = system.file("TU", "utsname", "utsname.c.001t.tu", package = "RGCCTUFFI")
tu = parseTU(tu.file)
r = getRoutines(tu)
r.uname = resolveType(r$uname, tu)
code = createRFunc(r.uname, returnInputs = "FALSE")
ds = getDataStructures(tu)
ds.utsname = resolveType(ds$utsname, tu)
scode = defStructClass(ds.utsname)
define(list(code, scode))
u = utsnameRef()
uname(u)
names(u)
u[]
u$sysname
################
# Alternatively, we can use genTUInterface() to do everything
# for us in a single call. But we lose some control, e.g.
# setting the returnInputs.
code = genTUInterface(tu.file, pattern = "utsname|uname")
# now we can evaluate/load/define the code in this R session
# including the uname() function.
define(code)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.