如何从我的c扩展中使rdoc正确读取方法参数?

时间:2021-09-27 10:53:05

all, I'm using rdoc to generate documentation for my Ruby code which contains C-extensions, but I'm having problems with my method arguments. Rdoc doesn't parse their names correctly and instead uses p1, p2 etc.

所有,我正在使用rdoc生成包含C扩展的Ruby代码的文档,但是我的方法参数有问题。 Rdoc没有正确解析它们的名称,而是使用p1,p2等。

So, first off, my extensions are actually compiled as C++ so I have to use function definitions that look like this:

所以,首先,我的扩展实际上编译为C ++,所以我必须使用如下所示的函数定义:

static VALUE 
MyMethod(VALUE self, VALUE flazm, VALUE saszm)
{
    return Qnil;
}

It looks like rdoc expects old style "C" definitions like this:

它看起来像rdoc期望这样的旧样式“C”定义:

static VALUE
MyMethod(self, flazm, saszm)
    VALUE self;
    VALUE flazm;
    VALUE saszm;
{
    return Qnil;
}

Is there anyway I can make this work?

无论如何我能做到这一点吗?

1 个解决方案

#1


RDoc is completely clueless about argument names in C extensions*. This is how RDoc compiles the string of arguments:

RDoc对C扩展*中的参数名称完全无能为力。这是RDoc编译参数字符串的方式:

meth_obj.params = "(" + (1..p_count).map{|i| "p#{i}"}.join(", ") + ")"

Changing your source formatting won't help.

更改源格式无济于事。

To improve your documentation, you could use the call-seq directive. You can specify one or more ways to invoke your method, which will be used instead of the default method(p1, p2) stuff.

要改进文档,可以使用call-seq指令。您可以指定一种或多种方法来调用您的方法,这将使用它来代替默认方法(p1,p2)。

/*
 * call-seq:
 *   my_method(flazm, saszm) -> nil
 *   my_method(bunny) { |fluffy_ears| ... } -> true or false
 *
 * Method description here.
 */
static VALUE 
MyMethod(VALUE self, VALUE flazm, VALUE saszm)
{
    return Qnil;
}

* It is clueless about some other things as well. Regex-based "parsing" is very naive.

*对其他一些事情也毫无头绪。基于正则表达式的“解析”非常幼稚。

#1


RDoc is completely clueless about argument names in C extensions*. This is how RDoc compiles the string of arguments:

RDoc对C扩展*中的参数名称完全无能为力。这是RDoc编译参数字符串的方式:

meth_obj.params = "(" + (1..p_count).map{|i| "p#{i}"}.join(", ") + ")"

Changing your source formatting won't help.

更改源格式无济于事。

To improve your documentation, you could use the call-seq directive. You can specify one or more ways to invoke your method, which will be used instead of the default method(p1, p2) stuff.

要改进文档,可以使用call-seq指令。您可以指定一种或多种方法来调用您的方法,这将使用它来代替默认方法(p1,p2)。

/*
 * call-seq:
 *   my_method(flazm, saszm) -> nil
 *   my_method(bunny) { |fluffy_ears| ... } -> true or false
 *
 * Method description here.
 */
static VALUE 
MyMethod(VALUE self, VALUE flazm, VALUE saszm)
{
    return Qnil;
}

* It is clueless about some other things as well. Regex-based "parsing" is very naive.

*对其他一些事情也毫无头绪。基于正则表达式的“解析”非常幼稚。