2010-05-28 57 views
1

下面是我认为是一个列表的漂亮标准头。因为struct 指向自身,所以我们需要这个两部分声明。说它listicle.h我怎样才能让swig包装一个链表式结构?

typedef struct _listicle listicle; 

struct _listicle{ 
    int i; 
    listicle *next; 
};  

我试图让痛饮来包装这个,让Python的用户可以使用listicle 结构的。下面是我在listicle.i现在:

%module listicle 

%{ 
#include "listicle.h" 
%} 

%include listicle.h 
%rename(listicle) _listicle; 

%extend listicle { 
    listicle() {return malloc (sizeof(listicle));} 
} 

你可以通过我来这里问说,这是行不通的。所有各种组合 我已经尝试过以各自的特殊方式失败。 [这一个:%extend defined for an undeclared class listicle。将其更改为%extend _listicle(并修复构造函数)并在Python中加载type object '_listicle' has no attribute '_listicle_swigregister'。等等。]

对此有何建议?

回答

0

也许你可以忽略python代码中的下一个指针,并且只需要在python中调用next()函数?或者,也许我不明白是什么问题...