summaryrefslogtreecommitdiff
path: root/lib/python/test/pyhello
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/test/pyhello')
-rw-r--r--lib/python/test/pyhello/Makefile8
-rw-r--r--lib/python/test/pyhello/src/hello.cpp41
2 files changed, 49 insertions, 0 deletions
diff --git a/lib/python/test/pyhello/Makefile b/lib/python/test/pyhello/Makefile
new file mode 100644
index 0000000000..0846f1002c
--- /dev/null
+++ b/lib/python/test/pyhello/Makefile
@@ -0,0 +1,8 @@
+BASE = ../../../..
+
+HOST_PROGRAMS = hello.so
+hello.so_SOURCES = hello.cpp
+hello.so_MODULES = lib/python
+hello.so_LDLIBS = -fPIC -shared
+
+include $(BASE)/common/make/top.mk
diff --git a/lib/python/test/pyhello/src/hello.cpp b/lib/python/test/pyhello/src/hello.cpp
new file mode 100644
index 0000000000..bd766f7401
--- /dev/null
+++ b/lib/python/test/pyhello/src/hello.cpp
@@ -0,0 +1,41 @@
+#include <boost/python/class.hpp>
+#include <boost/python/module.hpp>
+#include <boost/python/def.hpp>
+#include <iostream>
+#include <string>
+
+namespace {
+
+ class hello
+ {
+ public:
+ hello(const std::string& country) { this->country = country; }
+ std::string greet() const { return "Hello from " + country; }
+ private:
+ std::string country;
+ };
+
+ std::string invite(const hello& w) {
+ return w.greet() + "! Please come soon!";
+ }
+
+ std::string greet(const std::string& name, const std::string& country) {
+ return "Hello " + name + " from " + country;
+ }
+}
+
+BOOST_PYTHON_MODULE(hello)
+{
+ using namespace boost::python;
+ class_<hello>("hello", init<std::string>())
+ // Add a regular member function.
+ .def("greet", &hello::greet)
+ // Add invite() as a member of hello!
+ .def("invite", invite)
+ ;
+
+ // Also add invite() as a regular function to the module.
+ def("invite", invite);
+
+ def("greet", greet);
+}