Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions clingwrapper/src/clingwrapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,50 @@ bool Cppyy::CheckDatamember(TCppScope_t scope, const std::string& name) {
return (bool) Cpp::LookupDatamember(name, scope);
}

bool Cppyy::IsLambdaClass(TCppType_t type) {
return Cpp::IsLambdaClass(type);
}

Cppyy::TCppScope_t Cppyy::WrapLambdaFromVariable(TCppScope_t var) {
std::ostringstream code;
std::string name = Cppyy::GetFinalName(var);
code << "namespace __cppyy_internal_wrap_g {\n"
<< " " << "std::function " << name << " = ::" << Cpp::GetQualifiedName(var) << ";\n"
<< "}\n";

if (Cppyy::Compile(code.str().c_str())) {
TCppScope_t res = Cpp::GetNamed(name, Cpp::GetScope("__cppyy_internal_wrap_g"));
if (res) return res;
}
return var;
}

Cppyy::TCppScope_t Cppyy::AdaptFunctionForLambdaReturn(TCppScope_t fn) {
std::string fn_name = Cpp::GetQualifiedCompleteName(fn);
std::string signature = Cppyy::GetMethodSignature(fn, true);

std::ostringstream call;
call << "(";
for (size_t i = 0, n = Cppyy::GetMethodNumArgs(fn); i < n; i++) {
call << Cppyy::GetMethodArgName(fn, i);
if (i != n - 1)
call << ", ";
}
call << ")";

std::ostringstream code;
static int i = 0;
std::string name = "lambda_return_convert_" + std::to_string(++i);
code << "namespace __cppyy_internal_wrap_g {\n"
<< "auto " << name << signature << "{" << "return std::function(" << fn_name << call.str() << "); }\n"
<< "}\n";
if (Cppyy::Compile(code.str().c_str())) {
TCppScope_t res = Cpp::GetNamed(name, Cpp::GetScope("__cppyy_internal_wrap_g"));
if (res) return res;
}
return fn;
}

// std::string Cppyy::GetDatamemberName(TCppScope_t scope, TCppIndex_t idata)
// {
// TClassRef& cr = type_from_handle(scope);
Expand Down
6 changes: 6 additions & 0 deletions clingwrapper/src/cpp_cppyy.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ namespace Cppyy {
// RPY_EXPORTED
// std::string GetDatamemberName(TCppScope_t scope, TCppIndex_t idata) { return ""; }
RPY_EXPORTED
bool IsLambdaClass(TCppType_t type);
RPY_EXPORTED
TCppScope_t WrapLambdaFromVariable(TCppScope_t var);
RPY_EXPORTED
TCppScope_t AdaptFunctionForLambdaReturn(TCppScope_t fn);
RPY_EXPORTED
TCppType_t GetDatamemberType(TCppScope_t data);
RPY_EXPORTED
std::string GetDatamemberTypeAsString(TCppScope_t var);
Expand Down
Loading