00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #include <game.h>
00024
00025 template<class cusString>
00026 struct cusString_python
00027 {
00028 cusString_python()
00029 {
00030 boost::python::converter::registry::push_back(&convertible,&construct,boost::python::type_id<cusString>());
00031 }
00032
00033 static PyObject* convert(cusString const& s)
00034 {
00035 return boost::python::incref(boost::python::object(stringc(s).c_str()).ptr());
00036 }
00037
00038 static void* convertible(PyObject* obj_ptr)
00039 {
00040 if (!PyString_Check(obj_ptr)) return 0;
00041 return obj_ptr;
00042 }
00043
00044 static void construct(PyObject* obj_ptr,boost::python::converter::rvalue_from_python_stage1_data* data)
00045 {
00046 const char* value = PyString_AsString(obj_ptr);
00047 if (value == 0) boost::python::throw_error_already_set();
00048 void* storage = ((boost::python::converter::rvalue_from_python_storage<cusString>*)data)->storage.bytes;
00049 new (storage) cusString(value);
00050 data->convertible = storage;
00051 }
00052 };
00053
00054 stringc reprPos(position2d<s32>* pos)
00055 {
00056 return stringc("pos2d<X=") + stringc(pos->X) + ",Y=" + stringc(pos->Y) + ">";
00057 }
00058
00059 stringc reprDim(dimension2d<s32>* dim)
00060 {
00061 return stringc("dim2d<W=") + stringc(dim->Width) + ",H=" + stringc(dim->Height) + ">";
00062 }
00063
00064 BOOST_PYTHON_MODULE(pyIrr)
00065 {
00066 to_python_converter< stringw,cusString_python<stringw> >();
00067 cusString_python<stringw>();
00068 to_python_converter< stringc,cusString_python<stringc> >();
00069 cusString_python<stringc>();
00070 ;
00071 class_< position2d<s32> >("pos2d")
00072 .def(init<s32,s32>())
00073 .add_property("X", &position2d<s32>::X )
00074 .add_property("Y", &position2d<s32>::Y )
00075 .def("__repr__", &reprPos)
00076
00077 ;
00078 class_< dimension2d<s32> >("dim2d")
00079 .def(init<s32,s32>())
00080 .add_property("W", &dimension2d<s32>::Width )
00081 .add_property("H", &dimension2d<s32>::Height )
00082 .def("__repr__", &reprDim)
00083 ;
00084 }
00085