mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 16:32:16 +00:00
* Made Cygwin archiving reliable, even when the user supplies a path with backslashes ---------------------------------------------------------------------- Modified Files: tools/build/gcc-tools.jam tools/build/new/boost-build.jam boost/python/detail/config.hpp libs/python/build/Jamfile libs/python/example/do_it_yourself_convts.cpp libs/python/example/dvect.cpp libs/python/example/example1.cpp libs/python/example/getting_started1.cpp libs/python/example/getting_started2.cpp libs/python/example/ivect.cpp libs/python/example/nested.cpp libs/python/example/noncopyable_export.cpp libs/python/example/noncopyable_import.cpp libs/python/example/pickle1.cpp libs/python/example/pickle2.cpp libs/python/example/pickle3.cpp libs/python/example/richcmp1.cpp libs/python/example/richcmp2.cpp libs/python/example/richcmp3.cpp libs/python/example/rwgk1.cpp libs/python/example/simple_vector.cpp libs/python/test/comprehensive.cpp Added Files: libs/python/example/rwgk2.cpp libs/python/example/rwgk3.cpp ---------------------------------------------------------------------- [SVN r11705]
46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
// Example by Ralf W. Grosse-Kunstleve
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
namespace { // Avoid cluttering the global namespace.
|
|
|
|
// A friendly class.
|
|
class hello
|
|
{
|
|
public:
|
|
hello(const std::string& country) { this->country = country; }
|
|
std::string greet() const { return "Hello from " + country; }
|
|
private:
|
|
std::string country;
|
|
};
|
|
|
|
// A function taking a hello object as an argument.
|
|
std::string invite(const hello& w) {
|
|
return w.greet() + "! Please come soon!";
|
|
}
|
|
}
|
|
|
|
#include <boost/python/class_builder.hpp>
|
|
namespace python = boost::python;
|
|
|
|
BOOST_PYTHON_MODULE_INIT(getting_started2)
|
|
{
|
|
// Create an object representing this extension module.
|
|
python::module_builder this_module("getting_started2");
|
|
|
|
// Create the Python type object for our extension class.
|
|
python::class_builder<hello> hello_class(this_module, "hello");
|
|
|
|
// Add the __init__ function.
|
|
hello_class.def(python::constructor<std::string>());
|
|
// Add a regular member function.
|
|
hello_class.def(&hello::greet, "greet");
|
|
|
|
// Add invite() as a regular function to the module.
|
|
this_module.def(invite, "invite");
|
|
|
|
// Even better, invite() can also be made a member of hello_class!!!
|
|
hello_class.def(invite, "invite");
|
|
}
|