I just came up with my first working INPUT custom type-map that converts a hash-ref into an aa_renderparams C-struct. Looks slightly untypical for a typemap but it gets the job done quite nicely:
HV *h = (HV*)SvRV($arg);
$var = (aa_renderparams*)safemalloc(sizeof(aa_renderparams));
val = hv_fetch(h, \"-bright\", 7, FALSE);
$var->bright = val ? (int) SvIV(*val) : 0;
val = hv_fetch(h, \"-contrast\", 9, FALSE);
$var->contrast = val ? (int) SvIV(*val) : 127;
You really gotta love these typemaps.
After a while one starts to understand how XS works: It's basically one big preprocessor. xsubpp takes the default typemap plus your custom one and along with that runs through your
I wonder how long it took other people to find it out (I was probably one of the slower chaps).
And before I forget! Kudos to nicholas for his ExtUtils::Constant module. I followed his advice to use 5.8.0 as development environment, passed the -b switch to h2xs and am happy ever since! It even produced a test-file for all the constants (something I previously had to do myself for
MP3::Mplib). I was a little anxious at first because I thought that using this module would clearly infer some extra work (like some adaptions to the Makefile.PL or so) to make it work properly. But none at all! All worked splendidly out of the box. Thanks, Nick!