Integrate python scripts in c++ app -
i need extend c++ app python scripts i'm unsure interface library should use. basic communication is: c++ app registers class methods script (so loaded module in script), calls specific function in python script. script should perform task while being able call c++ methods. when script has finished, c++ app should able use return value of script (e.g. std::list).
from i've read boost.python pretty powerful , considering fact use boost, seems way go. in documentation, have not seen way expose class methods (static or not) python script.
is possible? how can that?
edit:
ok, think should have been little more specific, sorry. know how import python libraries etc. c++ code , i've taken boost documentation regarding embedding didn't got looking for.
for clarity, workflow in scenario:
- c++ app starts running
- at point, c++ class needs support specific python script located somewhere @ defined plugin-location on hard disk.
- before calling script, c++ class wants expose of methods script callbacks (the script should able call methods time, i.e. when script has finished execution , gets invoked place in c++ app, should not able call class methods anymore. also, don't want expose whole class script - specific methods , script should not able create instances of class. furthermore, don't want other python scripts able call exposed methods, 1 i'm going call.)
- after "registering" class methods script, c++ app calls needed function in script , gets return value c++ type (e.g. std::list)
i think third point tricky part here , i've no idea how can achieve this...
is possible?
absolutely, yes.
how can that?
in general sense,
import python libraries with:
boost::python::object obj = boost::python::import("module_name");
access library objects , subobjects , functions with:
obj.attr("name");
that should enough going - further, details in the documentation.
(example:)
auto calendar = boost::python::import( "calendar" ); auto leap = calendar.attr("isleap")("2015");
Comments
Post a Comment