【问题标题】:pyd wrap_class example does not compilepyd wrap_class 示例无法编译
【发布时间】:2016-03-17 16:32:51
【问题描述】:

我对 D 相当陌生,并尝试使用 pyd 框架为我的第一个代码实现一个 python 包装器。我遵循http://svn.dsource.org/projects/pyd/trunk/raw_html/class_wrapping.html 提供的示例代码,但 wrap_class 的配方似乎失败了。我的代码sn-p

import pyd.pyd;
import pyd.class_wrap;

class Foo {
    int m_i;

    this() { m_i = 0; }
    this(int j) { m_i = j; }
    this(int j, int k) { m_i = j + k; }

    int i() { return m_i; }
    void i(int j) { m_i = j; }

    void foo(char[] s) {
        import std.stdio;
        writefln(s, m_i);
    }

    Foo opAdd(Foo rhs) {
        return new Foo(m_i + rhs.m_i);
    }
}


extern(C) void PydMain() {
    module_init();

    // Call wrap_class
    wrap_class!(
        Foo,
        // Wrap the "foo" method
        Def!(Foo.foo),
        // Wrap the "i" property
        Property!(Foo.i),
        // Wrap the constructors.
        Init!(void function(int), void function(int, int))
    );
}

本质上是从示例中复制而来的,但无法计算并出现以下错误:

/usr/local/lib/python2.7/dist-packages/pyd/infrastructure/pyd/class_wrap.d(526): Error: tuple index 0 exceeds 0
/usr/local/lib/python2.7/dist-packages/pyd/infrastructure/pyd/class_wrap.d(534): Error: template instance pyd.class_wrap.Init!(void function(int), void function(int, int)).Init.Inner!(Foo) error instantiating
/usr/local/lib/python2.7/dist-packages/pyd/infrastructure/pyd/make_wrapper.d(126):        instantiated from here: shim!(2LU, Foo)
/usr/local/lib/python2.7/dist-packages/pyd/infrastructure/pyd/make_wrapper.d(136):        4 recursive instantiations from here: class_decls!(0u, Foo, Def!(foo), Property!(i), Init!(void function(int), void function(int, int)))
/usr/local/lib/python2.7/dist-packages/pyd/infrastructure/pyd/class_wrap.d(1483):        instantiated from here: make_wrapper!(Foo, Def!(foo), Property!(i), Init!(void function(int), void function(int, int)))
/usr/local/lib/python2.7/dist-packages/pyd/infrastructure/pyd/class_wrap.d(1476):        instantiated from here: _wrap_class!(Foo, "Foo", "", "", Def!(foo), Property!(i), Init!(void function(int), void function(int, int)))
pystochcalc.d(35):        instantiated from here: wrap_class!(Foo, Def!(foo), Property!(i), Init!(void function(int), void function(int, int)))
error: command 'dmd' failed with exit status 1

有谁知道这条错误消息告诉我什么以及如何修复它?谢谢!

【问题讨论】:

    标签: d pyd


    【解决方案1】:

    dsource 的 pyd 已过时。使用来自 GitHub 的 pyd - https://github.com/ariovistus/pyd 。例如,检查/examples 文件夹。查看 /examples/wrap 中的示例,该示例展示了如何执行这些操作。

    【讨论】:

    • 我按照 github 的示例进行了相同的编译。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 2011-07-23
    • 2020-09-13
    • 2018-12-02
    • 2014-06-10
    • 1970-01-01
    相关资源
    最近更新 更多