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)

  1. #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.
  2. 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.
  3. initialize your perl instance(s) as perlembed.pod says you to.
  4. 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");
  5. 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...


In reply to Re: Re: Re: embedded perl calls c subroutines by Courage
in thread embedded perl calls c subroutines by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.