Register function with namespace

Open
#262 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
54/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp, r
Domain
tooling

Research direction

Start in R/register.R at the wrapper-generation code linked in the issue, then trace how decor records namespaced functions and how R-side functions are generated. Add or extend tests for registering foo::bar and verify that the generated extern "C" wrapper and R-side function use valid names. The existing comparison branch may provide useful context.

Written by the indexing model from the issue text.

Description

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.

Dominant language
C++
Stars
224
Forks
52
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from r-lib/cpp11

All issues in r-lib/cpp11

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.