r-lib / cpp11

cpp11 helps you to interact with R objects using C++ code.
https://cpp11.r-lib.org/
Other
193 stars 46 forks source link

Register function with namespace #262

Open nbenn opened 2 years ago

nbenn commented 2 years ago

When registering a function in a namespace such as

[[cpp11::register]] int foo::bar(int a) {
  return a;
}

decor recognizes the function name as foo::bar and all would be fine (as far as I can tell), if the generated extern "C" wrapper

https://github.com/r-lib/cpp11/blob/c22dc9b611fe7d56ddfc57add2e01b1424869c0f/R/register.R#L171-L176

would not blindly forward the ::. Some further minor adjustments are required for the generation of the R-side functions. For the R-side function name, we could for example strip away anything that comes before the last scope resolution operator.

I started putting something together under https://github.com/r-lib/cpp11/compare/main...nbenn:main and I'm happy to clean this up a bit, add some tests and submit a PR.