-
Notifications
You must be signed in to change notification settings - Fork 0
/
typemap
82 lines (73 loc) · 1.63 KB
/
typemap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
TYPEMAP
int T_IV
dReal T_NV
dReal * T_ARRAY
dVector3 O_VEC3
dVector4 O_VEC4
dBodyID T_PTR
dGeomID T_PTR
dSpaceID T_PTR
dWorldID T_PTR
INPUT
O_OBJECT
if ( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) ) {
void** pointers = (void**)(SvIV( (SV*)SvRV($arg) ));
$var = ($type)(pointers[0]);
} else if ( $arg == 0 ) {
XSRETURN(0);
} else {
XSRETURN_UNDEF;
}
# These are copies of the T_ARRAY typemap.
O_VEC3
U32 ix_$var = $argoff;
$var = $ntype(items -= $argoff);
while ( items-- ) {
DO_ARRAY_ELEM;
ix_$var++;
}
/* this is the number of elements in the array */
ix_$var -= $argoff
O_VEC4
U32 ix_$var = $argoff;
$var = $ntype(items -= $argoff);
while ( items-- ) {
DO_ARRAY_ELEM;
ix_$var++;
}
/* this is the number of elements in the array */
ix_$var -= $argoff
OUTPUT
# The Perl object is blessed into 'CLASS', which should be a
# char* having the name of the package for the blessing.
O_OBJECT
if ( $var ) {
void** pointers = malloc( 2 * sizeof(void*) );
pointers[0] = (void*)$var;
pointers[1] = (void*)PERL_GET_CONTEXT;
sv_setref_pv( $arg, CLASS, (void*)pointers );
} else {
XSRETURN_UNDEF;
}
# These are copies of the T_ARRAY typemap, but modified to accept
# fixed sized arrays of double values.
O_VEC3
{
U32 v_index;
EXTEND( SP, 3 );
for ( v_index = 0; v_index < 3; v_index++ ) {
ST( v_index ) = sv_newmortal();
sv_setnv( ST(v_index), (double)${var}[v_index] );
}
XSRETURN(3);
}
O_VEC4
{
U32 v_index;
EXTEND( SP, 4 );
for ( v_index = 0; v_index < 4; v_index++ ) {
ST( v_index ) = sv_newmortal();
sv_setnv( ST(v_index), (double)${var}[v_index] );
}
XSRETURN(4);
}