in reply to perlxs failed to parse my typemap
Why not use T_ENUM?
Why not do the string-to-flag conversion in pure-perl?
Have you read perlxstypemap#Writing typemap Entries?
It says Each INPUT or OUTPUT typemap entry is a double-quoted Perl string that will be evaluated in the presence of certain variables to get the final C code for mapping a certain C type.
typemap file is mostly perl code
Try perl -S -MCarp::Always xsubpp -typemap test_typemap test.xs -output test.cpp 2>2
With this typemap
TYPEMAP geno_eye::LabelBind GENO_EYE_LABEL_BIND_T INPUT GENO_EYE_LABEL_BIND_T char* sv_text = SvPV_nolen($arg); $var = 0; if ( strstr(sv_text, \"top\") || strstr(sv_text, \"TOP\") ) +{ $var |= geno_eye::LABEL_BIND_TOP; } else if (strstr(sv_text, \"bottom\") || strstr(sv_text, \"BOTTOM +\")) { $var |= geno_eye::LABEL_BIND_BOTTOM; } if (strstr(sv_text, \"left\") || strstr(sv_text, \"LEFT\")) { $var |= geno_eye::LABEL_BIND_LEFT; } else if (strstr(sv_text, \"right\") || strstr(sv_text, \"RIGHT\" +)){ $var |= geno_eye::LABEL_BIND_RIGHT; } OUTPUT GENO_EYE_LABEL_BIND_T if ($var|geno_eye::LABEL_BIND_TOP) { sv_setpv($arg, \"top\"); } else if ($var|geno_eye::LABEL_BIND_BOTTOM) { sv_setpv($arg, \"bottom\"); } if ($var|geno_eye::LABEL_BIND_LEFT) { sv_catpv($arg, \"left\"); } else if ($var|geno_eye::LABEL_BIND_RIGHT) { sv_catpv($arg, \"right\"); }
It spits out
XS_EUPXS(XS_Test_test); /* prototype to pass -Wmissing-prototypes */ XS_EUPXS(XS_Test_test) { dVAR; dXSARGS; if (items != 1) croak_xs_usage(cv, "value"); { geno_eye__LabelBind value; char* sv_text = SvPV_nolen(ST(0)); value = 0; if ( strstr(sv_text, "top") || strstr(sv_text, "TOP") ) { value |= geno_eye::LABEL_BIND_TOP; } else if (strstr(sv_text, "bottom") || strstr(sv_text, "BOTTOM")) + { value |= geno_eye::LABEL_BIND_BOTTOM; } if (strstr(sv_text, "left") || strstr(sv_text, "LEFT")) { value |= geno_eye::LABEL_BIND_LEFT; } else if (strstr(sv_text, "right") || strstr(sv_text, "RIGHT")){ value |= geno_eye::LABEL_BIND_RIGHT; } ; #line 53 "test.xs" std::cout << "binary value: " << value << std::endl; #line 226 "test.cpp" } XSRETURN_EMPTY; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perlxs failed to parse my typemap (typemaps are double quoted perl strings)
by llancet (Friar) on Mar 12, 2014 at 07:17 UTC |