简体   繁体   English

通过SWIG从Python中的C函数返回Struct数据类型

[英]Return Struct data type from C-function in Python via SWIG

I have a C-function which returns a struct data type with several items in it (size_t, char*, int, unsigned and other structs). 我有一个C函数,该函数返回一个结构数据类型,其中包含多个项(size_t,char *,int,unsigned和其他结构)。 When I call this function there is no output in python. 当我调用此函数时,python中没有输出。 After some googling I think the problem is that I didn't declare the data type in my interface file. 经过一番谷歌搜索后,我认为问题是我没有在接口文件中声明数据类型。 But this turns out to be not that easy. 但是事实并非如此简单。 What is the right approach: typemaps or just a simple typedef ? 正确的方法是什么:类型映射还是简单的typedef

Can someone help me? 有人能帮我吗?

You need to %include the header first. 您需要先%include标题。 You need the headers for the nested structs too, in dependency order! 您还需要按照依赖关系顺序嵌套结构的标头!

After you've done that, Swig should automatically wrap the struct so that a call to your function will return a proxy object with the appropriate members. 完成此操作后,Swig应该自动包装该结构,以便对函数的调用将返回具有适当成员的代理对象。

A typemap is for when you want to change Swig's default behaviors. 类型映射用于您想要更改Swig的默认行为的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM