Do not afraid to shoot your leg? You're brave man!
I did "glueing" that way: (nothing unusual, I just read perlembed and related documentation)
- #include <EXTERN.h>, #include <perl.h> somewhere at the very top of C program. #include "xsub.h" somewhere near the end, and after that all "glue" functions are placed. All those header files are in perl/lib/CORE/* directory.
- Write "glue" functions like following example:
XS(TStringsTIEARRAY) {
dXSARGS;
SV *ssv=ST(0); // "G::TStrings"
void* tmp[4];
memset(tmp,0,sizeof(tmp));
tmp[2] = 0;
((TStrings*)(tmp[0])) = TyingStrings;
((TComponent*)(tmp[1])) = TyingComp;
((int)(tmp[2])) = TyingOpt;
SV *tsv;
tsv = newSVpv((char*)&tmp[0],16);
STRLEN len;
char *ptr = SvPV(ssv,len);
HV *stash = gv_stashpvn(ptr,len, TRUE);
SV *rsv = newRV_inc(tsv);
sv_bless(rsv,stash);
ST(0) = rsv;
XSRETURN(1);
}
Note usage of XS macro, "real" name of function will be more complicated after expansion of that macro.
- initialize your perl instance(s) as perlembed.pod says you to.
- After initializing it/them, in order to make those functions visible to perl, do something like:
newXS("G::TStrings::TIEARRAY", TStringsTIEARRAY, "BCB+Perl interna
+l");
- you may want to also run following:
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, "blablabla")
+;
to enable dynamic loading of modules.
And remember, I do not enCourage you to do that :)
Courage, the Cowardly Dog
things, I do for love to perl... | [reply] [d/l] [select] |
thanks for the hardcore version, nice to see the simple way, but i'll do the middle way between h2xs and this one, which would be the one you mentioned before.
i'll write the xs glue at the bottom of main.xs convert it with xsubpp and link with the help of ExtUtils.
so i stay portable (between perl versions and/or platforms) ;-)
thanks for your help, i'll vote for your solution as soon as i've set up a real account :-)
| [reply] |
| [reply] |