win32: exposing python scripts as .dll's

Syver Enstad syver-en+usenet at online.no
Thu Mar 20 23:14:16 CET 2003


David Abrahams <dave at boost-consulting.com> writes:

> 
> If you can stand C++, 

I can, used to love it in fact. After I discovered python and
smalltalk I find that life's too short for doing much else than
low level work in C++.


> I think doing something like that with
> Boost.Python would be relatively trivial.  An (untested) sketch:
> 
> // Retrieve the python module
> object pymodule(
>     handle<>(borrowed(PyImport_AddModule("module_name"))) );
> 
> // Now expose some of its functions:
> int __declspec(dllexport) f1(char const* s, int x)
> {
>     static object f = pymodule.attr("f1");
>     return extract<int>(f(s,x));
> }
> 
> std::string __declspec(dllexport) f2(double x)
> {
>     static object f = pymodule.attr("f2");
>     return extract<std::string>(f(x));
> }
> ...

That looks nice, it looks like it wouldn't be hell to generate this
code from a python module + some way of specifying the types.

-- 

Vennlig hilsen 

Syver Enstad




More information about the Python-list mailing list