diff --git a/src/CPPDataMember.cxx b/src/CPPDataMember.cxx index cb75654..109aa2b 100644 --- a/src/CPPDataMember.cxx +++ b/src/CPPDataMember.cxx @@ -324,16 +324,22 @@ PyTypeObject CPPDataMember_Type = { //- public members ----------------------------------------------------------- void CPyCppyy::CPPDataMember::Set(Cppyy::TCppScope_t scope, Cppyy::TCppScope_t data) { + if (Cppyy::IsLambdaClass(Cppyy::GetDatamemberType(data))) { + fScope = Cppyy::WrapLambdaFromVariable(data); + } else { + fScope = data; + } + fEnclosingScope = scope; - fScope = data; - fOffset = Cppyy::GetDatamemberOffset(data, scope); // XXX: Check back here // TODO: make lazy - fFlags = Cppyy::IsStaticDatamember(data) ? kIsStaticData : 0; + fOffset = Cppyy::GetDatamemberOffset(fScope, fScope == data ? scope : Cppyy::GetScope("__cppyy_internal_wrap_g")); // XXX: Check back here // TODO: make lazy + fFlags = Cppyy::IsStaticDatamember(fScope) ? kIsStaticData : 0; - const std::string name = Cppyy::GetFinalName(data); + const std::string name = Cppyy::GetFinalName(fScope); Cppyy::TCppType_t type; - if (Cppyy::IsEnumConstant(data)) { - type = Cppyy::GetEnumConstantType(data); + + if (Cppyy::IsEnumConstant(fScope)) { + type = Cppyy::GetEnumConstantType(fScope); fFullType = Cppyy::GetTypeAsString(type); if (fFullType.find("(anonymous)") == std::string::npos && fFullType.find("(unnamed)") == std::string::npos) { @@ -344,14 +350,14 @@ void CPyCppyy::CPPDataMember::Set(Cppyy::TCppScope_t scope, Cppyy::TCppScope_t d type = Cppyy::ResolveType(type); fFlags |= kIsConstData; } else { - type = Cppyy::GetDatamemberType(data); + type = Cppyy::GetDatamemberType(fScope); fFullType = Cppyy::GetTypeAsString(type); // Get the integer type if it's an enum if (Cppyy::IsEnumType(type)) type = Cppyy::ResolveType(type); - if (Cppyy::IsConstVar(data)) + if (Cppyy::IsConstVar(fScope)) fFlags |= kIsConstData; } diff --git a/src/CPPMethod.cxx b/src/CPPMethod.cxx index a3d9e66..a193faa 100644 --- a/src/CPPMethod.cxx +++ b/src/CPPMethod.cxx @@ -341,10 +341,11 @@ CPyCppyy::CPPMethod::CPPMethod( fMethod(method), fScope(scope), fExecutor(nullptr), fArgIndices(nullptr), fArgsRequired(-1) { - Cppyy::TCppType_t result = Cppyy::ResolveType(Cppyy::GetMethodReturnType(fMethod)); - if (TypeReductionMap.contains(result)) { + Cppyy::TCppType_t result = Cppyy::ResolveType(Cppyy::GetMethodReturnType(fMethod)); + if (TypeReductionMap.contains(result)) fMethod = Cppyy::ReduceReturnType(fMethod, TypeReductionMap[result]); - } + if (result && Cppyy::IsLambdaClass(result)) + fMethod = Cppyy::AdaptFunctionForLambdaReturn(fMethod); } //---------------------------------------------------------------------------- diff --git a/src/Cppyy.h b/src/Cppyy.h index 1daa410..2212ff3 100644 --- a/src/Cppyy.h +++ b/src/Cppyy.h @@ -325,6 +325,11 @@ namespace Cppyy { std::string GetDatamemberName(TCppScope_t scope, TCppIndex_t idata); CPPYY_IMPORT TCppScope_t ReduceReturnType(TCppScope_t fn, TCppType_t reduce); + bool IsLambdaClass(TCppType_t type); + CPPYY_IMPORT + TCppScope_t WrapLambdaFromVariable(TCppScope_t var); + CPPYY_IMPORT + TCppScope_t AdaptFunctionForLambdaReturn(TCppScope_t fn); CPPYY_IMPORT TCppType_t GetDatamemberType(TCppScope_t var); CPPYY_IMPORT