Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to export Nim procedures with native Nim types #6

Open
Vindaar opened this issue Oct 9, 2021 · 0 comments
Open

Allow to export Nim procedures with native Nim types #6

Vindaar opened this issue Oct 9, 2021 · 0 comments

Comments

@Vindaar
Copy link
Member

Vindaar commented Oct 9, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant