Ok, I've been through perlxstut, and I'm pretty comfortable there.  I
just wish it had one more example covering something like this.  Maybe
I'll patch it for this when I get all done.

What I have is a library that essentially populates a structure (the
memory for which the caller is assumed to have allocated) and then
performs calculations on that structure.  An example main() and the
library code is at the end of this message.

So now I've graduated to "perlxs" because xstut doesn't cover this
situation.  And I'm not quite sure what I need.  In my .xs file, I've
got:


        void
        populate(payroll)
        struct pinfo *  payroll

        void
        calculate(payroll)
        struct pinfo *  payroll

But of course, perl doesn't know what a "struct pinfo *" is.  I think I
need a TYPEMAP for this, but I'm not sure exactly how to proceed.  The
example in perlxs confuses me when I get to the part about "Netconfig
*T_PTROBJ".  What is this?  I was just hoping to get the structure
stored in a perl scalar that I could unpack as I needed... What's this
typemap file and where does it go, and what should it be named?  Do I
need an INPUT and OUTPUT section?

And why does perlxs muddle the discussion about passing structures back
and forth with a discussion about perl namespaces?  That just confuses
me further.

Help!

If anyone could help me wade through just this one section, I would be
so grateful.



===== A sample use of the library ====
----- contents of main.c -------

#include <stdio.h>
#include <stdlib.h>
#include "library.h"

int
main(int argc, char **argv)
{
        struct pinfo *payroll;

        payroll=(struct pinfo *)malloc(sizeof (struct pinfo));
        populate(payroll);
        printf("Name: %s\n", payroll->name);

        calculate(payroll);
        printf("Net: %f\n", payroll->net);

        exit(0);
}


===== The test library ======
----- contents of mylib.c -------

#include "./mylib.h"
#include <string.h>

void
populate(payroll)
struct pinfo *    payroll;
{
        payroll->gross=1000;
        payroll->tax_percent=.28;
        strcpy(payroll->name, "Clinton");
}

void
calculate(payroll)
struct pinfo *    payroll;
{
        payroll->net=payroll->gross-
                (payroll->gross * payroll->tax_percent);

}

----- contents of mylib.h -------
struct pinfo {
        char name[50];
        double gross;
        double tax_percent;
        double net;
};

extern void populate( struct pinfo *);
extern void calculate( struct pinfo *);


-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours! 
  [EMAIL PROTECTED]         for details see http://www.geeksalad.org
"If you rush a Miracle Man, 
        you get rotten Miracles." --Miracle Max, The Princess Bride

Reply via email to