Language-Befunge-Vector-XS

 view release on metacpan or  search on metacpan

XS.xs  view on Meta::CPAN

# my @vals = $vec->get_all_components;
#
# Get the values for all dimensions, in order from 0..N.
#
void
get_all_components( self )
        SV*  self;
    PREINIT:
        IV   dim, i, val;
        AV*  my_array;
    PPCODE:
        /* fetch the underlying array of the object */
        my_array = (AV*)SvRV(self);
        dim = av_len(my_array);

        /* extend the return stack and populate it */
        EXTEND(SP,dim+1);
        for ( i=0; i<=dim; i++ ) {
            val = SvIV( *av_fetch(my_array, i, 0) );
            PUSHs( sv_2mortal( newSViv(val) ) );
        }

XS.xs  view on Meta::CPAN

#
# Set the vector back to the origin, all 0's.
#
void
clear( self )
        SV*  self;
    INIT:
        IV   dim, i;
        SV*  zero;
        AV*  my_array;
    PPCODE:
        /* fetch the underlying array of the object */
        my_array = (AV*)SvRV(self);
        dim = av_len(my_array);

        /* clear each slot */
        for ( i=0; i<=dim; i++ ) {
            zero = newSViv(0);
            av_store(my_array, i, zero);
        }



( run in 1.480 second using v1.01-cache-2.11-cpan-5511b514fd6 )