for example, I have
例如,我有
my_types.h
typedef uint16_t my_type_1;
typedef uint8_t my_type_2;
my_types.c
int my_func(my_type_1 * arg1, my_type_2 * arg2, my_type_3 *arg3)
{
*args3 = *arg1 + *arg2;
return 0;
}
how do I define the interface file to have this wrapped to python?
如何定义接口文件以将其包装为python?
1 个解决方案
#1
0
Assuming you don't have a declaration of my_func
in my_types.h as well then your interface can become:
假设你在my_types.h中没有my_func的声明,那么你的界面可以变成:
%module test
%{
#include "my_types.h"
%}
%include <stdint.i>
%include "my_types.h"
%apply uint16_t *INPUT { my_type_1 * arg1 };
%apply uint8_t *INPUT { my_type_2 * arg2 };
%apply uint16_t *OUTPUT { my_type_1 *arg3 };
int my_func(my_type_1 * arg1, my_type_2 * arg2, my_type_1 *arg3);
This is sufficient to allow you to use it as follows:
这足以让您按如下方式使用它:
import test
print test.my_func(100, 50)[1]
Your "real" return is position 0 in the tuple, the first OUTPUT is at position 1.
您的“真实”返回是元组中的位置0,第一个OUTPUT位于位置1。
#1
0
Assuming you don't have a declaration of my_func
in my_types.h as well then your interface can become:
假设你在my_types.h中没有my_func的声明,那么你的界面可以变成:
%module test
%{
#include "my_types.h"
%}
%include <stdint.i>
%include "my_types.h"
%apply uint16_t *INPUT { my_type_1 * arg1 };
%apply uint8_t *INPUT { my_type_2 * arg2 };
%apply uint16_t *OUTPUT { my_type_1 *arg3 };
int my_func(my_type_1 * arg1, my_type_2 * arg2, my_type_1 *arg3);
This is sufficient to allow you to use it as follows:
这足以让您按如下方式使用它:
import test
print test.my_func(100, 50)[1]
Your "real" return is position 0 in the tuple, the first OUTPUT is at position 1.
您的“真实”返回是元组中的位置0,第一个OUTPUT位于位置1。