diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index 113e26c..8fdd89c 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -724,8 +724,9 @@ int getArgCount(PyObject *object) { return result; } -template -struct Functor0_converter + +template +struct Functor_converter { struct FunctorWrapper @@ -738,23 +739,23 @@ struct Functor0_converter m_Callable = bpy::object(); } - RET operator()() { + RET operator()(const PARAMS &...params) { GILock lock; - return (RET) m_Callable(); + return (RET) m_Callable(params...); } boost::python::object m_Callable; }; - Functor0_converter() + Functor_converter() { - bpy::converter::registry::push_back(&convertible, &construct, bpy::type_id>()); + bpy::converter::registry::push_back(&convertible, &construct, bpy::type_id>()); } static void *convertible(PyObject *object) { if (!PyCallable_Check(object) - || (getArgCount(object) != 0)) { + || (getArgCount(object) != sizeof...(PARAMS))) { return nullptr; } return object; @@ -763,100 +764,8 @@ struct Functor0_converter static void construct(PyObject *object, bpy::converter::rvalue_from_python_stage1_data *data) { bpy::object callable(bpy::handle<>(bpy::borrowed(object))); - void *storage = ((bpy::converter::rvalue_from_python_storage>*)data)->storage.bytes; - new (storage) std::function(FunctorWrapper(callable)); - data->convertible = storage; - } -}; - - -template -struct Functor1_converter -{ - - struct FunctorWrapper - { - FunctorWrapper(boost::python::object callable) : m_Callable(callable) { - } - - ~FunctorWrapper() { - GILock lock; - m_Callable = bpy::object(); - } - - RET operator()(const PAR1 ¶m1) { - GILock lock; - return (RET) m_Callable(param1); - } - - boost::python::object m_Callable; - }; - - Functor1_converter() - { - bpy::converter::registry::push_back(&convertible, &construct, bpy::type_id>()); - } - - static void *convertible(PyObject *object) - { - if (!PyCallable_Check(object) - || (getArgCount(object) != 1)) { - return nullptr; - } - return object; - } - - static void construct(PyObject *object, bpy::converter::rvalue_from_python_stage1_data *data) - { - bpy::object callable(bpy::handle<>(bpy::borrowed(object))); - void *storage = ((bpy::converter::rvalue_from_python_storage>*)data)->storage.bytes; - new (storage) std::function(FunctorWrapper(callable)); - data->convertible = storage; - } -}; - - -template -struct Functor2_converter -{ - - struct FunctorWrapper - { - FunctorWrapper(boost::python::object callable) : m_Callable(callable) { - } - - ~FunctorWrapper() { - GILock lock; - m_Callable = bpy::object(); - } - - RET operator()(const PAR1 ¶m1, const PAR2 ¶m2) { - GILock lock; - return (RET) m_Callable(param1, param2); - } - - boost::python::object m_Callable; - }; - - Functor2_converter() - { - bpy::converter::registry::push_back(&convertible, &construct, bpy::type_id>()); - } - - static void *convertible(PyObject *object) - { - if (!PyCallable_Check(object) - || (getArgCount(object) != 2)) { - return nullptr; - } - return object; - } - - static void construct(PyObject *object, bpy::converter::rvalue_from_python_stage1_data *data) - { - bpy::object callable(bpy::handle<>(bpy::borrowed(object))); - void *storage = ((bpy::converter::rvalue_from_python_storage>*)data)->storage.bytes; - new (storage) std::function(FunctorWrapper(callable)); + void *storage = ((bpy::converter::rvalue_from_python_storage>*)data)->storage.bytes; + new (storage) std::function(FunctorWrapper(callable)); data->convertible = storage; } }; @@ -963,10 +872,10 @@ BOOST_PYTHON_MODULE(mobase) // TODO: ISaveGameInfoWidget bindings - Functor1_converter(); - Functor1_converter(); - Functor1_converter(); - Functor2_converter(); + Functor_converter(); + Functor_converter(); + Functor_converter(); + Functor_converter(); bpy::class_("IOrganizer") .def("createNexusBridge", bpy::pure_virtual(&IOrganizer::createNexusBridge), bpy::return_value_policy()) @@ -1108,7 +1017,7 @@ BOOST_PYTHON_MODULE(mobase) bpy::to_python_converter>(); QFlags_from_python_obj(); - Functor0_converter(); // converter for the onRefreshed-callback + Functor_converter(); // converter for the onRefreshed-callback bpy::enum_("PluginState") .value("missing", IPluginList::STATE_MISSING) @@ -1132,7 +1041,7 @@ BOOST_PYTHON_MODULE(mobase) bpy::to_python_converter>(); QFlags_from_python_obj(); - Functor2_converter(); // converter for the onModStateChanged-callback + Functor_converter(); // converter for the onModStateChanged-callback bpy::enum_("ModState") .value("exists", IModList::STATE_EXISTS)