3 # This file is part of Language::Befunge::Vector::XS.
4 # Copyright (c) 2008 Jerome Quelin, all rights reserved.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the same terms as Perl itself.
20 /* used for constructor new() */
22 void* intArrayPtr(int num) {
24 mortal = sv_2mortal( NEWSV(0, num * sizeof(intArray)) );
30 MODULE = Language::Befunge::Vector::XS PACKAGE = Language::Befunge::Vector::XS
36 # my $vec = LB::Vector->new( $x [, $y, ...] );
38 # Create a new vector. The arguments are the actual vector data; one
39 # integer per dimension.
42 new( class, array, ... )
53 /* create the object and populate it */
55 for ( i=0; i<ix_array; i++ ) {
56 val = newSViv( array[i] );
60 /* Return a blessed reference to the AV */
61 RETVAL = newRV_noinc( (SV *)self );
62 stash = gv_stashpv( class, TRUE );
63 sv_bless( (SV *)RETVAL, stash );
70 # my $vec = Language::Befunge::Vector::XS->new_zeroes( $dims );
72 # Create a new vector, set to the origin. The only argument is the dimension of
73 # the vector to be created.
75 # ->new_zeroes(2) is exactly equivalent to ->new([0,0])
78 new_zeroes( class, dimension )
89 /* create the object and populate it */
91 for ( i=0; i<dimension; i++ ) {
96 /* return a blessed reference to the AV */
97 RETVAL = newRV_noinc( (SV *)self );
98 stash = gv_stashpv( class, TRUE );
99 sv_bless( (SV *)RETVAL, stash );
110 # my $dims = $vec->get_dims;
112 # Return the number of dimensions, an integer.
119 RETVAL = av_len(self) + 1;
125 # my $val = $vec->get_component( $index );
127 # Return the value for dimension $index.
130 get_component( self, index )
135 if ( index < 0 || index > av_len(self) )
136 croak( "No such dimension!" );
137 RETVAL = SvIV( *av_fetch(self, index, 0) );
150 # $v1->_substract_inplace($v2);
153 # Substract $v2 to $v1, and stores the result back into $v1.
155 AV* _substract_inplace( v1, v2 )
169 if ( dimv1 != dimv2 )
170 croak("uneven dimensions in vector substraction!");
172 for ( i=0 ; i<=dimv1; i++ ) {
173 val1 = SvIV( *av_fetch(v1, i, 0) );
174 val2 = SvIV( *av_fetch(v2, i, 0) );
175 av_store( v1, i, newSViv(val1-val2) );
186 # my $bool = $v1->_compare($v2);
187 # my $bool = $v1 <=> $v2;
189 # Check whether the vectors both point at the same spot. Return 0 if they
190 # do, 1 if they don't.
193 _compare( v1, v2, variant )
208 if ( dimv1 != dimv2 )
209 croak("uneven dimensions in bounds check!");
212 for ( i=0 ; i<=dimv1; i++ ) {
213 val1 = SvIV( *av_fetch(v1, i, 0) );
214 val2 = SvIV( *av_fetch(v2, i, 0) );
215 if ( val1 != val2 ) {