代码之家  ›  专栏  ›  技术社区  ›  hyperlogic

如何使RDOC正确地从C扩展中读取方法参数?

  •  3
  • hyperlogic  · 技术社区  · 16 年前

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

    所以,首先,我的扩展实际上是编译为C++的,所以我必须使用看起来像这样的函数定义:

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

    看起来RDOC希望使用老式的“C”定义,如下所示:

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

    我能把这个做好吗?

    1 回复  |  直到 11 年前
        1
  •  3
  •   molf    16 年前

    RDOC完全不知道C扩展中的参数名*。这就是RDOC如何编译参数字符串:

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

    更改源格式没有帮助。

    为了改进文档,可以使用 call-seq 指令。您可以指定一个或多个方法来调用您的方法,将使用该方法而不是默认方法 method(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;
    }
    

    * 它对其他一些事情也一无所知。基于regex的“解析”非常幼稚。

    推荐文章