yard icon indicating copy to clipboard operation
yard copied to clipboard

YARD not working on C++ sources

Open sonots opened this issue 7 years ago • 5 comments

YARD does not successfully parse my C++ sources.

Steps to reproduce

rb_define_singleton_method(mMemoryPool, "enable", (VALUE(*)(ANYARGS))rb_memory_pool_enable, 0);
# the (VALUE(*)(ANYARGS)) cast is necessary for C++

Actual Output

No method documented.

Expected Output

Method document is generated.

Environment details:

  • OS: [Mac OSX and Ubuntu 16.04]
  • Ruby version (ruby -v): [2.4.1p111]
  • YARD version (yard -v): [0.9.2]

sonots avatar Mar 22 '18 12:03 sonots

I've found https://github.com/lsegal/yard/issues/697. As it states, (METHOD) works, but (VALUE(*)(ANYARGS)) does not work.

The problem now is that we do not have METHOD macro in ruby.h.

sonots avatar Mar 22 '18 12:03 sonots

I found that we can work around as:

rb_define_singleton_method(mMemoryPool, "enable", RUBY_METHOD_FUNC(rb_memory_pool_enable), 0);

RUBY_METHOD_FUNC(func) is defined in ruby.h.

sonots avatar Mar 22 '18 13:03 sonots

Is the workaround sufficient for your use case? I believe that solving this with more complex parsing might not be needed and would love to avoid it if possible.

lsegal avatar Aug 04 '18 00:08 lsegal

Didn't know the Ruby headers had a macro for that. We have been using our own macro for our C++ application: https://github.com/SketchUp/ruby-c-extension-examples/blob/master/Hello%20World/src/RubyUtils/RubyUtils.h#L21

That's been working for us, along with YARD now that it can handle C++ namespaces.

thomthom avatar Nov 19 '18 13:11 thomthom

I'm doing some issue gardening 🌱🌿 🌷 and came upon this issue. It seems outdated, with no activity for 5 years.

By closing some old issues we reduce the list of open issues to a more manageable set. Let me know if you think this is a mistake and that the issue should stay open.

To maintainers

Open the 'Discussions' tab on the repo. That way, much of what's in issues today can be easily moved to Discussions (there will be a dedicated button on each issue, after it's enabled).

sandstrom avatar Aug 25 '23 10:08 sandstrom