Re: python , Boost and straight (but complex) C code



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)
.



Relevant Pages

  • Re: location of using, include, and namespaces statement
    ... > directive now apply to the client's source file, too, if he ever ... > And would it help or hurt to put the 'using' directives inside ... your'e quite right - if namespace pollution is a concern [I suppose it ... > the header when you're not looking. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Source Tree Structure
    ... Repertory has the same meaning as Directory or as Folder. ... VStudio for VB.NET follows a different convention. ... > VS will add a namespace statement of "com.company.xxx.yyy" to the source? ... there is no relation between namespaces and the source file locations ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Source Tree Structure
    ... > VS will add a namespace statement of "com.company.xxx.yyy" to the source? ... VS will also append sub-directories to the namespace, so for a root ... namespace of X, if you create a source file in a folder within the project, ... does that mean that that's the typical convention that people ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Source Tree Structure
    ... with the following source file: ... VS will add a namespace statement of "com.company.xxx.yyy" to the source? ... By default, if you create a repertory and create a source file there, ... >> Newbie to .NET from Java, ...
    (microsoft.public.dotnet.languages.csharp)