【发布时间】:2017-10-02 10:33:13
【问题描述】:
对于以下简单函数:
#include <iostream>
void Echo(int no) {
std::cout << "no: " << no << std::endl;
}
我有以下swig接口文件:
%module example
%{
#include "example.h"
%}
%include "example.h"
我可以使用 swig 生成一个包装器并将其测试为:
from example import Echo
import numpy as np
no = 2
Echo( np.int(no) ) # OK
Echo( np.int32(no) ) # Error
Echo( np.int64(no) ) # Error
swig 生成类型检查包装器代码,导致第二次和第三次调用出错。这很好,但是有什么方法可以覆盖/禁用为合法的类型转换生成这种类型检查代码?
【问题讨论】:
-
您可以使用
%rename将Echo重命名为EchoInternal,并使用%insert("python")添加一个函数Echo,该函数将转换为int并调用EchoInternal。没有旗帜可以引入某种放松