Re: python , Boost and straight (but complex) C code
- From: Sebastian 'lunar' Wiesner <basti.wiesner@xxxxxxx>
- Date: Sat, 30 Dec 2006 14:16:50 +0100
Osiris <nono@xxxxxxxxxxx> typed
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>
iostream is a C++ header file...
#include <stdafx.h>
namespace { // Avoid cluttering the global namespace.
C doesn't know about namespaces. They are a C++ thing, too.
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 );
You include a C++ IO header, but use traditional C IO functions here.
Either you use C++ streams here, or you replace <iostream> with
<stdio.h>.
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 ?
May be... Didn't you try it?
It may also be, that you have to create a PyObject first...
--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
.
- References:
- python , Boost and straight (but complex) C code
- From: Osiris
- python , Boost and straight (but complex) C code
- Prev by Date: Re: python , Boost and straight (but complex) C code
- Next by Date: Re: Wow, Python much faster than MatLab
- Previous by thread: Re: python , Boost and straight (but complex) C code
- Next by thread: Re: python , Boost and straight (but complex) C code
- Index(es):
Relevant Pages
|