-
Notifications
You must be signed in to change notification settings - Fork 3
/
typemap
39 lines (34 loc) · 844 Bytes
/
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
TYPEMAP
char T_CHAR
int T_INT
int * T_PTR
float * T_PTR
float T_FLOAT
Entity * O_OBJECT
Collision * O_OBJECT
Point * O_OBJECT
Rect * O_OBJECT
Grid * O_OBJECT
Circle * O_OBJECT
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;
}
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;
}