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.
Assuming we had something like:
the
exportRpragma should make sure that the procedure is wrapped into another Nim procedure: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 underlyingSEXPdata. This is similar to what Rcpp does as well.