Tom Schindl <[EMAIL PROTECTED]> writes:
>Hi,
>
>how can I create an instance of a Perl-class in XS.
>
>
>1. Both defined in XS:
>======================
>Soccer.xs:
>-----------------------8<-----------------------
>MODULE = Soccer                PACKAGE = Soccer::Team
>
>Team *
>new(CLASS)
>     char *CLASS
>   CODE:
>     .......
>   OUTPUT:
>     RETVAL
>
>Player *
>Team::getPlayer(p_id)
>     int p_id
>   CODE
>     ## create a new player new Soccer::Player(p_id)
>     ## how is this done?????

Up to you ;-)

   It depends on what you have for the Player * typemap entry.

   Typically one has a C struct and a C "constructor" which 
   malloc()s a copy fills in the fields and returns it.
   Typemap then does sv_setref_pv() 

   Or you could minic perl, create a newHV() and fill in members
   and return a ref to the HV.


>
>
>MODULE = Soccer                PACKAGE = Soccer::Player
>
>Player *
>new(CLASS,p_id)
>     char *CLASS
>     int p_id
>   CODE:
>     .......
>   OUTPUT:
>     RETVAL
>-----------------------8<-----------------------
>
>
>2. 1 defined in XS 1 defined in Perl:
>=======================================
>Soccer.xs:
>-----------------------8<-----------------------
>MODULE = Soccer                PACKAGE = Soccer::Team
>
>Team *
>new(CLASS)
>     char *CLASS
>   CODE:
>     .......
>   OUTPUT:
>     RETVAL
>
>Player *
>Team::getPlayer(p_id)
>     int p_id
>   CODE
>     ## create a new player new Soccer::Player(p_id)
>     ## how is this done?????
>-----------------------8<-----------------------
>
>Soccer.pm:
>-----------------------8<-----------------------
>package Soccer::Player;
>
>sub new {
>   my $class = shift;
>   my $p_id  = shift;
>
>   return bless { id => $p_id }, $class;
>}
>-----------------------8<-----------------------

Reply via email to