我一直在探索 swig 接口的自动生成文档。使用带有 doxygen 注释的后端 C 文件并生成 python 接口。
我无法在为接口生成的文档字符串中捕获类型映射。
以下代码供参考:
C 标头中的示例:
/**
* @brief Factorial of a number
*
* Returns the factorial of a given input integer
*
* @param[in] n as an input integer
* @result n! as an ouput integer
*/
int fact(int n);
/**
* @brief Modulo of two numbers
*
* Calculates the modulo of given two input integers
*
* @param[in] x as an input integer
* @param[in] y as an input integer
* @param[out] res as an ouput integer which stores the modulo of x and y
* @result ouput integer which is the modulo of x and y
*/
int my_mod1(int x, int y, int *res);
示例界面:
%module example
%{
#include <example.h>
%}
%include "typemaps.i"
%apply int *OUTPUT { int *res };
%include <example.h>
尝试 1: swig4.0 中的 doxygen 标志完成了大部分工作,但没有 %feature("autodoc","1")。 @params[in/out] 仍然无法识别 swig 命令。
尝试2: doxy2swig 很有前途并且完成了大部分工作。但它似乎已被弃用。 https://github.com/m7thon/doxy2swig
但是我在 both 上述尝试中观察到的一个滞后事实是返回多个输出的类型映射没有按预期工作。我最终只得到以下 my_mod1 接口:
def my_mod1(x: "int", y: "int") -> "int *":