support python print for classes with print_ function

release/4.3a0
Duy-Nguyen Ta 2016-11-16 17:37:33 -05:00
parent 3f0304d067
commit dc185a6d30
1 changed files with 4 additions and 0 deletions

View File

@ -103,10 +103,14 @@ void Method::emit_cython_pxd(FileWriter& file, const Class& cls) const {
/* ************************************************************************* */
void Method::emit_cython_pyx(FileWriter& file, const Class& cls) const {
string funcName = pyRename(name_);
if (funcName == "print_")
file.oss << "\tdef __str__(self):\n\t\tself.print_('')\n\t\treturn ''\n";
size_t N = nrOverloads();
bool hasPrint = false;
for(size_t i = 0; i < N; ++i) {
// Function definition
file.oss << "\tdef " << funcName;
if (funcName == "print_") hasPrint = true;
// modify name of function instantiation as python doesn't allow overloads
// e.g. template<T={A,B,C}> funcName(...) --> funcNameA, funcNameB, funcNameC
// TODO: handle overloading properly!! This is lazy...