From 817f8d72388567103d291e72cf7a75c63b254285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sat, 2 May 2020 15:05:24 +0200 Subject: [PATCH] Fix variants() method of GuessedValue. --- src/runner/pythonrunner.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index bb3a5e0..31fd0f1 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -1140,7 +1140,15 @@ BOOST_PYTHON_MODULE(mobase) // Use an intermediate lambda to avoid having to register the std::function conversion: .def("setFilter", +[](GuessedValue* gv, bpy::object fn) { gv->setFilter(fn); }) - .def("variants", &MOBase::GuessedValue::variants, bpy::return_value_policy()) + // Exposing the set does not work, but even if it worked, we would lose the order since it would be + // converted to a python set() so we expose a cusotm iterator. This works because variants() returns + // a reference, otherwize this would be more complex to do (also, needs to use references instead of + // pointers instead of the lambda due to the range() requirements): + .def("variants", bpy::range< + bpy::return_value_policy>( + +[](GuessedValue &gv) { return std::begin(gv.variants()); }, + +[](GuessedValue &gv) { return std::end(gv.variants()); } + )) .def("__str__", &MOBase::GuessedValue::operator const QString&, bpy::return_value_policy()) ;