在用网上 http://www.swig.org/translations/chinese/tutorial.html 的example调试时还是碰到了很多问题,国内TCL跟C的资料也不多,搞了好久终于可以把C语言中的变量读出来了,example算是成功了。
首先把
/* File : example.c */
#include <time.h>
double My_variable = 3.0;
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
int my_mod(int x, int y) {
return (x%y);
}
char *get_time()
{
time_t ltime;
time(<ime);
return ctime(<ime);
}
以这个example为例,首先编写接口文件:
/* example.i */
%module example
%{
/* Put header files here or function declarations like below */
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);