77
88namespace py = pybind11;
99
10+ bool CallPythonFunction (void * item, py::function& func) {
11+ py::object result =func (item);
12+ return py::cast<bool >(result);
13+ }
1014
11- void define_List (py::module_& m)
15+ PYBIND11_MODULE (List, m)
1216{
1317py::class_<BList>(m," BList" )
1418.def (py::init<int >()," " ,py::arg (" count" )=20 )
@@ -33,15 +37,24 @@ py::class_<BList>(m, "BList")
3337.def (" ItemAtFast" , &BList::ItemAtFast," " ,py::arg (" index" ))
3438.def (" LastItem" , &BList::LastItem," " )
3539.def (" Items" , &BList::Items," " )
36- .def (" HasItem" , py::overload_cast<void *>(&BList::HasItem)," " ,py::arg (" item" ))
37- .def (" HasItem" , py::overload_cast<const void *>(&BList::HasItem)," " ,py::arg (" item" ))
38- .def (" IndexOf" , py::overload_cast<void *>(&BList::IndexOf)," " ,py::arg (" item" ))
39- .def (" IndexOf" , py::overload_cast<const void *>(&BList::IndexOf)," " ,py::arg (" item" ))
40+ .def (" HasItem" , py::overload_cast<void *>(&BList::HasItem, py::const_ )," " ,py::arg (" item" ))
41+ .def (" HasItem" , py::overload_cast<const void *>(&BList::HasItem, py::const_ )," " ,py::arg (" item" ))
42+ .def (" IndexOf" , py::overload_cast<void *>(&BList::IndexOf, py::const_ )," " ,py::arg (" item" ))
43+ .def (" IndexOf" , py::overload_cast<const void *>(&BList::IndexOf, py::const_ )," " ,py::arg (" item" ))
4044.def (" CountItems" , &BList::CountItems," " )
4145.def (" IsEmpty" , &BList::IsEmpty," " )
42- .def (" DoForEach" , py::overload_cast<bool (*func)(void *item)>(&BList::DoForEach)," " ,py::arg (" " ))
43- .def (" DoForEach" , py::overload_cast<bool (*func)(void *item,void *arg2),void *>(&BList::DoForEach)," " ,py::arg (" " ),py::arg (" arg2" ))
44- ;
45-
46+ // .def("DoForEach", py::overload_cast<bool(*func)(void*item)>(&BList::DoForEach), "", py::arg(""))
47+ .def (" DoForEach" , [](BList& self,py::function& func,void * item) ->void {
48+ self.DoForEach (static_cast <bool (*)(void *,void *)>(+[](void * item,void * userData) ->bool {
49+ return CallPythonFunction (item, *static_cast <py::function*>(userData));
50+ }), item);
51+ }," " ,py::arg (" func" ),py::arg (" item" ))
4652
53+ // .def("DoForEach", py::overload_cast<bool(*func)(void*item,void*arg2), void *>(&BList::DoForEach), "", py::arg(""), py::arg("arg2"))
54+ .def (" DoForEach" , [](BList& self, py::function& func,void * arg2) ->void {
55+ self.DoForEach (static_cast <bool (*)(void *,void *)>(+[](void * item,void * userData) ->bool {
56+ return CallPythonFunction (item, *static_cast <py::function*>(userData));
57+ }), arg2);
58+ }," " ,py::arg (" func" ),py::arg (" arg2" ))
59+ ;
4760}