Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 71 lines (53 sloc) 1.602 kB
46d9cce @arnsholt Functionality and tests for callbacks.
arnsholt authored
1 use lib '.';
2 use t::CompileTestLib;
3 use NativeCall;
4 use Test;
5
79429d9 @arnsholt Return values from callbacks seem to work now as well.
arnsholt authored
6 plan(9);
46d9cce @arnsholt Functionality and tests for callbacks.
arnsholt authored
7
8 compile_test_lib('08-callbacks');
9
10 class Struct is repr('CStruct') {
11 has Str $.str;
12 has int $.ival;
79429d9 @arnsholt Return values from callbacks seem to work now as well.
arnsholt authored
13
14 method init {
15 $!str := 'Tweedledum, tweedledee';
16 $!ival = 314;
17 }
46d9cce @arnsholt Functionality and tests for callbacks.
arnsholt authored
18 }
19
20 sub TakeACallback(&cb()) is native('./08-callbacks') { * }
21 sub TakeIntCallback(&cb(int)) is native('./08-callbacks') { * }
22 sub TakeStringCallback(&cb(Str)) is native('./08-callbacks') { * }
23 sub TakeStructCallback(&cb(Struct)) is native('./08-callbacks') { * }
24
79429d9 @arnsholt Return values from callbacks seem to work now as well.
arnsholt authored
25 sub CheckReturnsFloat(&cb(--> num)) is native('./08-callbacks') { * }
26 sub CheckReturnsStr(&cb(--> Str)) is native('./08-callbacks') { * }
27 sub CheckReturnsStruct(&cb(--> Struct)) is native('./08-callbacks') { * }
28
46d9cce @arnsholt Functionality and tests for callbacks.
arnsholt authored
29 sub simple_callback() {
30 pass 'simple callback';
31 }
32
33 sub int_callback(int $x) {
34 is $x, 17, 'int callback argument'
35 }
36
37 sub str_callback(Str $x) {
38 is $x, 'lorem ipsum', 'string callback argument'
39 }
40
41 sub struct_callback(Struct $struct) {
42 is $struct.str, 'foobar', 'struct callback string argument';
43 is $struct.ival, -42, 'struct callback int argument';
44 }
45
79429d9 @arnsholt Return values from callbacks seem to work now as well.
arnsholt authored
46 sub return_float() returns num {
47 return 1.23e0;
48 }
49
50 sub return_str() returns Str {
51 return 'Herps and derps';
52 }
53
54 sub return_struct() returns Struct {
55 my Struct $struct .= new;
56 $struct.init;
57
58 return $struct;
59 }
60
46d9cce @arnsholt Functionality and tests for callbacks.
arnsholt authored
61 TakeACallback(&simple_callback);
62 TakeIntCallback(&int_callback);
63 TakeStringCallback(&str_callback);
64 TakeStructCallback(&struct_callback);
65
79429d9 @arnsholt Return values from callbacks seem to work now as well.
arnsholt authored
66 CheckReturnsFloat(&return_float);
67 CheckReturnsStr(&return_str);
68 CheckReturnsStruct(&return_struct);
69
46d9cce @arnsholt Functionality and tests for callbacks.
arnsholt authored
70 # vim:ft=perl6
Something went wrong with that request. Please try again.