diff --git a/example_external.cpp b/example_external.cpp new file mode 100644 index 0000000..17ef400 --- /dev/null +++ b/example_external.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +int main(){ + + try{ + + pylingual py; + + py.call("x = 42"); + auto x = py.get("x"); + cout << x << endl; + + return 0; + + + }catch(boost::python::error_already_set const &){ + //Parse and output the exception + string perror_str = parse_python_exception(); + cout << "Error in Python: " << perror_str << endl; + } +} diff --git a/include/pylingual.hpp b/include/pylingual.hpp index dc932c2..2f2a4b9 100644 --- a/include/pylingual.hpp +++ b/include/pylingual.hpp @@ -53,6 +53,11 @@ class pylingual { return Vec; } + template + T get(const char* var_to_extract) { + return extract(main_module.attr(var_to_extract)); + } + template void call(const char* code_to_execute,char* var_to_extract,vector &output) { exec(code_to_execute,main_namespace);