RE: [C++-sig] BPL embedding tutorial updated.
From: Dirk Gerrits [mailto:dirk@gerrits.homeip.net]
I've made some changes to my Boost.Python tutorial on embedding. [...] If you find any errors or have any suggestions, I'd love to hear from you.
Great work! A minor nit though, embedding doesn't require static libraries (you can even mix and match), static libs does make distribution easier. Am I to assume that there will eventually be e.g. (apologies for the incorrect syntax, I assume you get the idea): object py::import::AddModule(std::string const& name); dict py::module::GetDict(object moduleObj); object py::RunExpr(std::string const& code, dict globals, dict locals); object py::RunStmt(std::string const& code, dict globals, dict locals); object py::RunStmts(std::string const& code, dict globals, dict locals); or is there even thought about wrapping more of the Python object types, like e.g.: module mainModule = py::import::AddModule("__main__"); dict mainDict = mainModule.getDict(); interpreter interp(mainDict, mainDict); // globals, locals object res = interp.runExpr(std::string const& code); etc. Either way would be quite cool IMHO :-) If you allready have a design in mind, you should make it available in case someone has time to help you <wink>. -- bjorn
Bjorn Pettersen wrote:
From: Dirk Gerrits [mailto:dirk@gerrits.homeip.net]
I've made some changes to my Boost.Python tutorial on embedding.
[...]
If you find any errors or have any suggestions, I'd love to hear from
you.
Great work! A minor nit though, embedding doesn't require static libraries (you can even mix and match), static libs does make distribution easier.
I was unaware. If you have some specific changes to suggest to the tutorial, please do! They will probably be too late for the 1.30.0 release though, I'm afraid.
Am I to assume that there will eventually be e.g. (apologies for the incorrect syntax, I assume you get the idea):
object py::import::AddModule(std::string const& name); dict py::module::GetDict(object moduleObj); object py::RunExpr(std::string const& code, dict globals, dict locals); object py::RunStmt(std::string const& code, dict globals, dict locals); object py::RunStmts(std::string const& code, dict globals, dict locals);
or is there even thought about wrapping more of the Python object types, like e.g.:
module mainModule = py::import::AddModule("__main__"); dict mainDict = mainModule.getDict(); interpreter interp(mainDict, mainDict); // globals, locals object res = interp.runExpr(std::string const& code);
etc.
Either way would be quite cool IMHO :-) If you allready have a design in mind, you should make it available in case someone has time to help you <wink>.
There has been some discussion on a python::interpreter class. Nothing has really been decided, but I think it would look something like this: namespace boost { namespace python { class interpreter { interpreter(); interpreter(int argc, char* argv[]); ~interpreter(); void exec(char const* statements); void exec(char const* statements, dict& globals, dict& locals); object eval(char const* expression); object eval(char const* expression, dict& globals, dict& locals); dict& main_namespace(); object* main_module(); }; }} // namespace boost::python The call i.exec/eval(statements) would be the same as the call i.exec/eval(statements, i.main_namespace(), i.main_namespace()) But I must stress here that this is 'email client code' not 'IDE source editor code'. Also, as I said above, nothing has been agreed on, this is still open for discussion. Regards, Dirk Gerrits
participants (2)
-
Bjorn Pettersen -
Dirk Gerrits