cpp11 icon indicating copy to clipboard operation
cpp11 copied to clipboard

Basic C++ to C++ API generation

Open nx10 opened this issue 3 years ago • 1 comments

This PR adds functionality to generate C/C++ APIs which can be accessed from other packages.

Motivation

  • Fast communication between packages
  • Manually creating the required registration and headers is cumbersome, error-prone and violates DRY principles

Implementation

Functions annotated with [[cpp11::external]] are registered in src/cpp11.cpp and a header inst/include/{package}_api.h is created which can be included in other packages after LinkingTo: and importing the package.

The generated code is inspired by similar APIs in systemfonts and some other packages.

Features:

  • There are two optional parameters for renaming the exported function and adding a doc comment [[cpp11::external("other_name", "Some documentation comment")]]
  • inst/include/{package}_types.h will be included in the header if it exists.

ToDo

  • Unit testing

Discussion

Please let me know if this is in scope for cpp11 (I hope so), or if you have any comments or suggestions.

Also thank you for your work on the cpp11 package!

nx10 avatar Mar 16 '22 20:03 nx10

cc @thomasp85 who might have interest in this approach.

jimhester avatar Aug 24 '22 17:08 jimhester