1 ! (c)2010 Joe Groff bsd license
2 USING: accessors alien alien.c-types alien.handles alien.syntax
3 destructors kernel math tools.test ;
4 IN: alien.handles.tests
6 TUPLE: thingy { x integer } ;
9 CALLBACK: int thingy-callback ( uint thingy-handle )
10 CALLBACK: int thingy-ptr-callback ( void* thingy-handle )
12 : test-thingy-callback ( -- alien )
13 [ alien-handle> x>> 1 + ] thingy-callback ;
15 : test-thingy-ptr-callback ( -- alien )
16 [ alien-handle-ptr> x>> 1 + ] thingy-ptr-callback ;
18 : invoke-test-thingy-callback ( thingy -- n )
19 test-thingy-callback int { uint } cdecl alien-indirect ;
20 : invoke-test-thingy-ptr-callback ( thingy -- n )
21 test-thingy-ptr-callback int { void* } cdecl alien-indirect ;
24 [ 5 <thingy> <alien-handle> &release-alien-handle [ alien-handle? ] keep ] with-destructors
29 [ 5 <thingy> <alien-handle-ptr> &release-alien-handle-ptr [ alien-handle-ptr? ] keep ] with-destructors
35 5 <thingy> <alien-handle> &release-alien-handle
36 invoke-test-thingy-callback
42 5 <thingy> <alien-handle-ptr> &release-alien-handle-ptr
43 invoke-test-thingy-ptr-callback