1

たとえば、私は

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;
}

これをPythonにラップするようにインターフェイスファイルを定義するにはどうすればよいですか?

4

1 に答える 1

0

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);

これは、次のように使用できるようにするのに十分です。

import test

print test.my_func(100, 50)[1]

「実際の」戻り値はタプルの位置 0 で、最初の OUTPUT は位置 1 にあります。

于 2013-03-24T08:50:08.277 に答える