2009-11-09 109 views
1

包装C的结构我有一个包含以下类型定义的C头文件:与SWIG

// example.h 
typedef struct Vertex { 
    int color; 
} Vertex; 

我试着来包装这个结构与痛饮,但显然我做错了什么。我痛饮接口文件看起来像

// example.i 
%module example 
%inline %{ 
#include "example.h" 
} 

但是,如果我在我的头文件中的内容复制到我的接口文件,使后者的样子

%module example 

%inline %{ 
typedef struct Vertex { 
    int color; 
} Vertex; 
%} 

我可以在Ruby访问结构在以下way

irb> require 'example' 
# => true 
irb> Examlpe::Vertex 
# => Vertex 

有没有办法自动换行头文件?我不想在每次更改它时将头文件的内容复制并粘贴到接口文件中。

在此先感谢您的帮助。

- T6D

回答

3

这已经有一段时间,因为我使用痛饮,但我记得%直列用于通过内嵌的部分直接向编译器; Swig本身没有看到它,我认为你需要的是:

%module example 
%include<example.h>