Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 43 lines (32 sloc) 0.97 kb
46d9cce @arnsholt Functionality and tests for callbacks.
arnsholt authored
1 use lib '.';
2 use t::CompileTestLib;
3 use NativeCall;
4 use Test;
5
6 plan(5);
7
8 compile_test_lib('08-callbacks');
9
10 class Struct is repr('CStruct') {
11 has Str $.str;
12 has int $.ival;
13 }
14
15 sub TakeACallback(&cb()) is native('./08-callbacks') { * }
16 sub TakeIntCallback(&cb(int)) is native('./08-callbacks') { * }
17 sub TakeStringCallback(&cb(Str)) is native('./08-callbacks') { * }
18 sub TakeStructCallback(&cb(Struct)) is native('./08-callbacks') { * }
19
20 sub simple_callback() {
21 pass 'simple callback';
22 }
23
24 sub int_callback(int $x) {
25 is $x, 17, 'int callback argument'
26 }
27
28 sub str_callback(Str $x) {
29 is $x, 'lorem ipsum', 'string callback argument'
30 }
31
32 sub struct_callback(Struct $struct) {
33 is $struct.str, 'foobar', 'struct callback string argument';
34 is $struct.ival, -42, 'struct callback int argument';
35 }
36
37 TakeACallback(&simple_callback);
38 TakeIntCallback(&int_callback);
39 TakeStringCallback(&str_callback);
40 TakeStructCallback(&struct_callback);
41
42 # vim:ft=perl6
Something went wrong with that request. Please try again.