[C++-sig] looking up functions

Alan Baljeu alanbaljeu at yahoo.com
Thu Nov 13 16:35:43 CET 2008


I cryptically wrote:

> As best I could figure, I needed to write Python code, execute a script file, get that code to call a C function that I register, in order to have that function.  At least the tutorial implied that was the way.

Which made Stefan respond:
>I'm confused. In your last mail you asked for how to get hold of a Python function so you could run it from within C++. Now you want to run a C function instead ?

I misspoke.  I want a Python function.  I was confused by the lack of any PyModule_GetFunction or anything resembling that in the API.

>Python is an interpreted language, so you need to read (interpret) the code that you then want to run. 
>I asked where the function that you want to store and run comes from. If it already exists in a module, 
>you can simply import that module (using boost::python::import()), and extract the function from it:

>object module = import("your_module");
>object function = module["your_function"];
>function(); // call it

I take it this is Boost?  I haven't looked at that.  I was just studying the built-in API.

>If you don't want to import a module directly, but rather run a script, use exec() instead.

>I'm not sure how this could be any simpler.

I agree.  This is exactly what I was looking for but failed to find.


      __________________________________________________________________
Get the name you've always wanted @ymail.com or @rocketmail.com! Go to http://ca.promos.yahoo.com/jacko/


More information about the Cplusplus-sig mailing list