Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-05-30 08:47:49


----- Original Message -----
From: "Pål Frogner Hansen" <pal_at_[hidden]>

> I'm looking for examples on how to get the integration C++/Python going!
>
> I am able to generate dll's that exposes a C++ interface to python
("pythonglue"). Great!
>
> What I want it to call functions inside a script from C++. In my game,
how can I, for example:
>
> [C++ code:]
> (init python)
> (load the script into memory)
> (setup variables, etc.)
>
> for all items on scene{
> call_a_function_from_the_loaded_script( "multiplexer_method",
cur_item );
> }
>
> The pythoncode looks something like this:
> import pythonglue # exposes the C++ api
> def multiplexer_method(object):
> # Call the function in the dict with the correct name
> return function_map[ "do"+object.__class__.__name__ ]()
>
> ...
>
> The main problem is to find the funtion
call_a_function_from_the_loaded_script in boost...

You have (at least) two choices:

1. Pass the function as a PyObject* into some C++ function you've wrapped
with Boost.Python so you have access to it from your for loop.

2. Use the Python 'C' API to get the module containing the Python function,
and call PyObject_GetAttrString() to get the function off the module.

> Also can I pass pointers as parameters?

If you mean, "can I pass pointers as parameters to the Python function I'm
calling?", I don't think that's well-supported in Boost.Python v1.
Boost.Python v2, which is in pre-release, has much better support for it.

> I want to add that any XXX_Run_File_XXX(FILE*)-methods typically crashes
too.

I have no idea what you're referring to here.

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk