From 163ed213ef2ef24f088e7b77d9345851b8f43e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Mon, 4 May 2020 20:09:24 +0200 Subject: [PATCH] Update the install() bindings to allow more flexibility and be easier to use. --- src/runner/proxypluginwrappers.cpp | 15 +++++++++------ src/runner/pythonrunner.cpp | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/runner/proxypluginwrappers.cpp b/src/runner/proxypluginwrappers.cpp index 861d919..320c601 100644 --- a/src/runner/proxypluginwrappers.cpp +++ b/src/runner/proxypluginwrappers.cpp @@ -310,7 +310,10 @@ IPluginInstaller::EInstallResult IPluginInstallerSimpleWrapper::install( { namespace bpy = boost::python; - using return_type = std::variant, std::tuple, QString, int>> ; + using return_type = std::variant< + IPluginInstaller::EInstallResult, + std::shared_ptr, + std::tuple, QString, int>> ; auto ret = basicWrapperFunctionImplementation(this, "install", boost::ref(modName), tree, version, nexusID); return std::visit([&](auto const& t) { @@ -322,11 +325,11 @@ IPluginInstaller::EInstallResult IPluginInstallerSimpleWrapper::install( tree = t; return IPluginInstaller::RESULT_SUCCESS; } - else if constexpr (std::is_same_v, QString, int>>) { - tree = std::get<0>(t); - version = std::get<1>(t); - nexusID = std::get<2>(t); - return IPluginInstaller::RESULT_SUCCESS; + else if constexpr (std::is_same_v, QString, int>>) { + tree = std::get<1>(t); + version = std::get<2>(t); + nexusID = std::get<3>(t); + return std::get<0>(t); } else { static_assert("Type not handled in boost::apply_visitor."); diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index 10fecc5..65c90b2 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -660,10 +660,13 @@ BOOST_PYTHON_MODULE(mobase) utils::register_associative_container(); // Tuple: - bpy::register_tuple, QString, int>>(); + bpy::register_tuple, QString, int>>(); // Variants: - bpy::register_variant, std::tuple, QString, int>>>(); + bpy::register_variant, + std::tuple, QString, int>>>(); bpy::register_variant>(); bpy::register_variant>(); @@ -1187,7 +1190,13 @@ BOOST_PYTHON_MODULE(mobase) ; bpy::class_("IPluginInstallerSimple") - .def("install", &IPluginInstallerSimple::install) + // Note: Keeping the variant here if we always return a tuple to be consistent with the wrapper and + // have proper stubs generation. + .def("install", +[](IPluginInstallerSimple* p, GuessedValue& modName, std::shared_ptr& tree, QString& version, int& nexusID) + -> std::variant, std::tuple, QString, int>> { + auto result = p->install(modName, tree, version, nexusID); + return std::make_tuple(result, tree, version, nexusID); + }) .def("parentWidget", &IPluginInstallerSimpleWrapper::parentWidget, bpy::return_value_policy()) .def("manager", &IPluginInstallerSimpleWrapper::manager, bpy::return_value_policy()) ;