Lists the constants of a library handle: each enumerator and #define
constant that ffi_cdef() or ffi_include() bound into it, and each
macro that ffi_include() expanded and could not bind as a constant,
with why. A #define with a long double operand is never bound, on
any platform, and is listed as skipped by either function. It is the
counterpart of ffi_functions(); a bound constant's value is
lib$NAME.
Arguments
- lib
A handle from
ffi_dlopen().
Value
A data frame with one row per constant, in the order bound
(within one set of declarations, enumerators before #defines; a
constant bound again moves to the end, as a function declared again
does in ffi_functions()): name; kind, the constant's C
kind, "integer" (an integer constant or an enumerator, which R
holds as an integer or, past R's integers, as a double), "double"
(a floating constant) or "string", and NA for a macro that was
skipped; and reason, NA when lib$NAME gives the value, and
otherwise why not: the error reading it raises (a value R cannot hold
exactly), or why the macro was skipped. A macro that names a function
the handle declares is the function, and not listed.
Examples
lib <- ffi_dlopen(if (.Platform$OS.type == "windows") "ucrtbase" else "m")
ffi_cdef(lib, "
enum mode { READ = 1, WRITE = 2 };
#define TWO_PI 6.283185307179586
#define NAME \"zuffi\"
#define HUGE_ID 9007199254740993
")
ffi_constants(lib)
#> name kind
#> 1 READ integer
#> 2 WRITE integer
#> 3 TWO_PI double
#> 4 NAME string
#> 5 HUGE_ID integer
#> reason
#> 1 <NA>
#> 2 <NA>
#> 3 <NA>
#> 4 <NA>
#> 5 The constant `HUGE_ID` is an integer that a double does not hold exactly.
ffi_close(lib)