python , Boost and straight (but complex) C code
- From: Osiris <nono@xxxxxxxxxxx>
- Date: Sat, 30 Dec 2006 13:49:37 +0100
I have these pieces of C-code (NOT C++ !!) I want to call from Python.
I found Boost.
I have MS Visual Studio 2005 with C++.
is this the idea:
I write the following C source file:
============================
#include <iostream>
#include <stdafx.h>
namespace { // Avoid cluttering the global namespace.
int my_int; /* a global integer: or outside namespace ? */
double calc ( double f)
{
my_int = (int) (f/2);
printf( "Half of %f is %d\n", f, my_int );
return f/2;
}
}
#include <boost/python.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE( half )
{
def("calc", calc );
}
================================
Which I put in a VC project and compile into a .DLL
This DLL I put somewhere on my disk, where Python 2.4 can find it.
then I write the following Python source:
=====================
from half import *
calc(34655.0)
et voila ?
Can I acces my_int too, this way ?
.
- Follow-Ups:
- Re: python , Boost and straight (but complex) C code
- From: Erik Max Francis
- Re: python , Boost and straight (but complex) C code
- From: Osiris
- Re: python , Boost and straight (but complex) C code
- From: Sebastian 'lunar' Wiesner
- Re: python , Boost and straight (but complex) C code
- From: Osiris
- Re: python , Boost and straight (but complex) C code
- Prev by Date: Re: per interpreter storage for C extensions
- Next by Date: Re: Scaling pictures
- Previous by thread: Re: Looking for python SIP/MGCP stacks
- Next by thread: Re: python , Boost and straight (but complex) C code
- Index(es):
Relevant Pages
|