This is the main user-facing function for API mode. It generates C code to compute field offsets using the compiler, compiles it, and returns a helper object with constructor and field metadata.
Value
An rffi_struct_helpers S3 object with:
- $new()
Constructor function that allocates a new struct
- $fields
Named list of field metadata (offset + FFIType)
- $get(ptr, field)
Get field value from struct pointer
- $set(ptr, field, value)
Set field value in struct pointer
- $lib
The compiled library object (for cleanup)
Examples
if (FALSE) { # \dontrun{
# Define struct with field types
helpers <- ffi_create_helpers(
"Point2D",
list(x = ffi_int(), y = ffi_int())
)
# Create instance
pt <- helpers$new()
# Set/get fields
helpers$set(pt, "x", 42L)
helpers$set(pt, "y", 100L)
helpers$get(pt, "x") # 42L
helpers$get(pt, "y") # 100L
# Access field metadata
helpers$fields$x$offset # 0
helpers$fields$y$offset # 4
} # }