summaryrefslogtreecommitdiff
path: root/lib/python/test/pyhello/src/hello.cpp
blob: bd766f7401ffed63ca0f8daa5e5c501ea749b7d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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);
}