I am new to "PerlEmbed" and "XS" topics.I am trying
to code a C interface
which calls perl subroutines,which inturn uses structures declared
within
the C program.Could anyone of you provide details of about this things.
I do created some perl modules using XS and tried to connect with my
C interface but I couldn't do it.
Here goes my trial,
// MyHeader.h
struct _mytest {
char *pcName;
int iNameLength;
};
h2xs -n mytest MyHeader.h
which resulted some files like Makefile.PL,MyHeader.xs etc.
I do edited the Makefile.PL and XS file for proper
set and get
methods for accessing structure variables.
// MyHeader.xs
typedef _mytest mytest;
MODULE = perltest PACKAGE = perltest
mytest *
getmytestinstance()
CODE:
RETVAL = (mytest*)malloc(sizeof
(mytest) );
OUTPUT:
RETVAL
void
setName( pmytestpar, pcNamePar )
mytest * pmytestpar
char *
pcNamePar
CODE:
pmytestpar->pcName = pcNamePar;
char *
getName( pmytestpar )
mytest * pmytestpar
CODE:
RETVAL = pmytestpar->pcName;
OUTPUT:
RETVAL
After this coding,I called "perl Makefile.PL",which
resulted with a C file and
a perl module.Now I am able to call "make && make test",which
works properly.
Now my problem is how to use this with my C interface
program,so that it
allocates some mytest structure and should be possible to pass them
test.pl.
I tried something like,
// Cinterface.h
#include <EXTERN.h>
#include <perl.h>
#include "MyHeader.h"
PerlInterpreter* myperlinterpreter;
...
typedef struct _mytest mytest;
mytest * mytesttmp = NULL;
mytesttmp = (mytest*) malloc(sizeof( mytest) );
SV* svtmp;
svsetref_pv( svtmp, "perltest", mytesttmp );
...
within my perl subroutine I want to use this but
I couldn't make
it and I don't how to do this.
If anybody helped me it will be greatful.
Thanks a lot in advance.
-- Mit freundlichen Grüßen / With Regards Panneer Selvam . M ____________________________________ Maas High Tech Software GmbH, Germany Connecting the Islands Tel: (+49) 711 / 77 - 917 - 0 http://www.maas.de http://www.afp2web.com