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]
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#include <string.h>
|
|
|
|
namespace hello {
|
|
class world
|
|
{
|
|
public:
|
|
world(int) {}
|
|
~world() {}
|
|
const char* get() const { return "hi, world"; }
|
|
};
|
|
|
|
size_t length(const world& x) { return strlen(x.get()); }
|
|
}
|
|
|
|
#include <boost/python/class_builder.hpp>
|
|
|
|
// Python requires an exported function called init<module-name> in every
|
|
// extension module. This is where we build the module contents.
|
|
BOOST_PYTHON_MODULE_INIT(hello)
|
|
{
|
|
// create an object representing this extension module
|
|
boost::python::module_builder hello("hello");
|
|
|
|
// Create the Python type object for our extension class
|
|
boost::python::class_builder<hello::world> world_class(hello, "world");
|
|
|
|
// Add the __init__ function
|
|
world_class.def(boost::python::constructor<int>());
|
|
// Add a regular member function
|
|
world_class.def(&hello::world::get, "get");
|
|
|
|
// Add a regular function to the module
|
|
hello.def(hello::length, "length");
|
|
}
|
|
|
|
// Win32 DLL boilerplate
|
|
#if defined(_WIN32)
|
|
#include <windows.h>
|
|
extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID)
|
|
{
|
|
return 1;
|
|
}
|
|
#endif // _WIN32
|