【サイト内の関連ページ】
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
%module example %{ #define SWIG_FILE_WITH_INIT #include "example.h" %} int fact(int n);
#include "example.h" int fact(int n) { if (n < 0){ /* This should probably return an error, but this is simpler */ return 0; } if (n == 0) { return 1; } else { /* testing for overflow would be a good idea here */ return n * fact(n-1); } }
int fact(int n);
#!/usr/bin/env python """ setup.py file for SWIG example """ from distutils.core import setup, Extension example_module = Extension('_example', sources=['example_wrap.c', 'example.c'], ) setup (name = 'example', version = '0.1', author = "SWIG Docs", description = """Simple swig example from docs""", ext_modules = [example_module], py_modules = ["example"], )
次のように操作する.
swig -python example.i python setup.py build_ext --inplace
import example example.fact(4)