Skip to content

Allow to export Nim procedures with native Nim types #6

@Vindaar

Description

@Vindaar

Assuming we had something like:

proc foo(x: int, y: NumericVector[float]) {.exportR.} =
   ...

the exportR pragma should make sure that the procedure is wrapped into another Nim procedure:

proc fooImpl(xImpl, yImpl: SEXP) 
  let x = xImpl.to(int)
  let y = yImpl.to(NumericVector[float])
  # ... original body

this way we can have native Nim types as arguments and let the user avoid doing the conversions, somewhat similar to Rcpp.

For scalar types copying the data is fine. For other types (e.g. vectors etc.) we want Nim wrapper types e.g. NumericVector[T], which keeps track internally of the underlying SEXP data. This is similar to what Rcpp does as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions