[C++-sig] looking up functions
seefeld at sympatico.ca
Thu Nov 13 16:23:24 CET 2008
Alan Baljeu 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.
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 ?
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
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.
...ich hab' noch einen Koffer in Berlin...
More information about the Cplusplus-sig