Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

swig hello world example

View !README.md
1 2 3 4 5 6
/_hello*.so
/build/
/hello.py
/hello_wrap.c
/MANIFEST
/dist/
View !README.md
1 2 3 4 5
include hello.h
include hello.c
include hello.py
include hello_wrap.c
include setup.py
View !README.md
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
python=python
 
all: test_hello
 
test_hello: test_hello.py _hello.so
$(python) test_hello.py
 
_hello.so: setup.py hello_wrap.c hello.h hello.c hello.i
$(python) setup.py build_ext --inplace
 
hello.py hello_wrap.c: hello.i
swig -python -o hello_wrap.c $<
 
sdist: setup.py hello.py hello_wrap.c
$(python) setup.py sdist
clean:
-rm hello.py hello_wrap.c _hello*.so *.pyc MANIFEST
-rm build/ dist/ __pycache__/ -rf
 
.PHONY: all test_hello clean sdist
View !README.md
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <stdio.h>
#include "hello.h"
 
double doublefun(double b){
printf("c(%g)",b);
return b+12.5;
}
 
float floatfun(float b){
printf("c(%f)",b);
return b+12.5;
}
 
int intfun(int b){
printf("c(%d)",b);
return b+12;
}
View !README.md
1 2 3
double doublefun(double b);
float floatfun(float b);
int intfun(int b);
View !README.md
1 2 3 4 5 6 7
%module hello
 
%{
#include "hello.h"
%}
 
%include "hello.h"
View !README.md
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import os
from distutils.core import setup, Extension
 
ext_module = Extension('_hello',
sources=['hello_wrap.c', 'hello.c'],
depends=['hello.h'],
)
 
setup (name = 'swig-hello-world-example',
version = '0.1',
description = "swig hello world example",
ext_modules = [ext_module],
py_modules = ["hello"],
)
View !README.md
1 2 3 4 5
import hello
 
print("i: %s" % hello.intfun(2))
print("f: %s" % hello.floatfun(2.3))
print("d: %s" % hello.doublefun(2.3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.