//--------------------------------------------------------------------------- ref_t PyW_IntVecToPyList(const intvec_t &intvec) { size_t c = intvec.size(); PYW_GIL_CHECK_LOCKED_SCOPE(); newref_t py_list(PyList_New(c)); for ( size_t i=0; i<c; i++ ) PyList_SetItem(py_list.o, i, PyInt_FromLong(intvec[i])); return ref_t(py_list); }
void pycohal::Converter_vec_uint32_from_list::construct ( PyObject* obj_ptr, bpy::converter::rvalue_from_python_stage1_data* data ) { // Grab pointer to memory in which to construct the new vector void* storage = ( ( bpy::converter::rvalue_from_python_storage< std::vector<uint32_t> >* ) data )->storage.bytes; // Grab list object from obj_ptr bpy::list py_list ( bpy::handle<> ( bpy::borrowed ( obj_ptr ) ) ); // Construct vector in requested location, and set element values. // boost::python::extract will throw appropriate exception if can't convert to type T ; boost::python will then call delete itself as well. size_t nItems = bpy::len ( py_list ); std::vector<uint32_t>* vec_ptr = new ( storage ) std::vector<uint32_t> ( nItems ); for ( size_t i=0; i<nItems; i++ ) { vec_ptr->at ( i ) = bpy::extract<uint32_t> ( py_list[i] ); } // If successful, then register memory chunk pointer for later use by boost.python data->convertible = storage; }
void on_select(const intvec_t &intvec) { PYW_GIL_GET; ref_t py_list(PyW_IntVecToPyList(intvec)); newref_t pyres(PyObject_CallMethod(self, (char *)S_ON_SELECT, "O", py_list.o)); }